2

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?}");
            });
        }
3
  • Not sure about linux but on windows I had to set this after the call to UseStaticFiles(): app.UseFileServer(new FileServerOptions { FileProvider = env.ContentRootFileProvider }); Commented May 12, 2020 at 15:19
  • Does it work for other file types, such as images, css, js, etc? Commented May 12, 2020 at 17:29
  • Nope it does not work for static files either. Commented May 12, 2020 at 18:08

1 Answer 1

1

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;
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.