Asp.Net Core Static Files

Viewed 479

Problem

So I was trying to place an HTML file in the wwwroot folder like that

wwwroot page.html

and it worked on the development machine, I could reach that page. However, on the server which is running on Nginx, It just doesn't want to display that page. The Nginx is configured just like in the documentation. I assume is something OS related or I don't know...



Here are the related configurations:


Program.cs

public class Program
    {
        public static void Main(string[] args)
        {
            CreateWebHostBuilder(args).Build().Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
         WebHost.CreateDefaultBuilder(args)
             .UseStartup<Startup>();
    }


Startup.cs

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // 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.UseRouting();

            app.UseAuthorization();

            var swaggerOptions = new Options.SwaggerOptions();
            Configuration.GetSection(nameof(swaggerOptions)).Bind(swaggerOptions);

            app.UseSwagger(option =>
            {
                option.RouteTemplate = swaggerOptions.JsonRoute;
            });

            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint(swaggerOptions.UiEndpoint, swaggerOptions.Description);
            });


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
1 Answers

I found the solution. The problem was in Nginx configuration as I expected. This is the chunk of code I added to /etc/nginx/sites-enabled/yourdomain ON TOP of proxy configuration

 location ~* /page {
                root /var/www/yourdomain/html;
        }
Related