Why js,css,lib didn't load from wwwroot?

Dondon510 221 Reputation points
2022-04-05T14:25:27.84+00:00

I made a simple ASP MVC (Net Core 3.1) , I leave it as standard, and deploy it under a subfolder of the Apache (/var/www/html/myapps/app/v1)

I started the kestrel without any errors, I access the page (ie. https://example.com/myapps/app/v1), it shows but some css, js, lib don't load properly (ERR_ABORTED 404 (Not Found), I see they are already in the www-root folder

this is weird for me, and stuck on this for almost 2 weeks, I need help.

thank s a lot in advance

Don

Failed to load resource: the server responded with a status of 404 (Not Found)

bootstrap.min.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)
bootstrap.bundle.min.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
jquery.min.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
site.js:1 Failed to load resource: the server responded with a status of 404 (Not Found)
/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
site.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)
bootstrap.min.css:1 Failed to load resource: the server responded with a status of 404 (Not Found)

and as default, all of the file references (.css, js, etc already been in the /wwwroot) and I already referenced them in _layout.cshtml

below my configs:

[root@iZk1aa2qin3uxnqh8agvrmZ ~]# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 16 2020 16:18:20
[root@iZk1aa2qin3uxnqh8agvrmZ ~]#

my kestrel

[Service]
WorkingDirectory=/var/www/html/prime/test/v1
ExecStart=/usr/bin/dotnet /var/www/html/prime/test/v1/WebApplication4.dll
Restart=always
RestartSec=10
KillSignal=SIGINT
SyslogIdentifier=dotnet-example
User=root
Environment=ASPNETCORE_ENVIRONMENT=Production
Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false
TimeoutStopSec=90

.my httpd.conf

<VirtualHost *:443>

ServerName apps.example.com
ServerAlias apps.example.com
ServerAdmin info@example.com

DocumentRoot /var/www/html

<Directory /var/www/html>
    Options -Indexes +FollowSymLinks
    AllowOverride All
</Directory>

<Location /myapps/test/v1/>
  ProxyPreserveHost On
  ProxyPass http://localhost:5003/
  ProxyPassReverse http://localhost:5003/
  Require all granted
</Location>

and last but not least, my startup.cs

 public class Startup
 { 
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddControllersWithViews();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();
        app.UsePathBase("/myapps/test/v1");

        app.UseRouting();

        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        });
    }
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,208 questions
0 comments No comments
{count} votes

13 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 56,931 Reputation points
    2022-04-08T20:06:51.563+00:00

    so did you

    dotnet run --urls=http://localhost:5003

    then open in browser:

    http://locahost:5003/prime/test/v1

    0 comments No comments

  2. Dondon510 221 Reputation points
    2022-04-09T01:02:10.273+00:00

    191456-works-on-local.png

    if works if I run it on local machine neither on centos 7

    [root@iZk1aa2qin3uxnqh8agvrmZ ~]# httpd -v
    Server version: Apache/2.4.6 (CentOS)
    Server built: Nov 16 2020 16:18:20

    I thought it's apache's issue, isn't it? or is there something need to adjust in my code to apply this on it?

    0 comments No comments

  3. Dondon510 221 Reputation points
    2022-04-11T02:34:50.153+00:00

    Everyone!, thanks for the clue.

    this already resolved!

    <Location /prime/test/v1/>
          ProxyPreserveHost On
          ProxyPass http://localhost:5003/prime/test/v1/
          ProxyPassReverse http://localhost:5003/prime/test/v1/
          Require all granted
        </Location>
    

    and the most important thing in program.cs

     public static void Main(string[] args)
            {
                CreateHostBuilder(args)
    #if !DEBUG
                    .UseContentRoot(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location))
    #endif
                    .Build().Run();
            }
    
            public static IHostBuilder CreateHostBuilder(string[] args) =>
               Host.CreateDefaultBuilder(args)
                   .ConfigureWebHostDefaults(webBuilder =>
                   {
                       webBuilder.UseStartup<Startup>().UseUrls("http://127.0.0.1:5002");
                   });
    
    0 comments No comments