首页 > 解决方案 > .net 将 https 连接到 nginx 时看不到静态文件

问题描述

我在 DotNet 项目上连接的 https 协议有问题。

我在cloudflare服务上创建了一个证书,上传到我的VPS服务器,但是,如果之前通过IP地址打开站点时,站点可以正常打开

http://xxx.xxx.xxx.xxx

但是当连接到https://example.com时,我在位于 wwwroot 目录中的静态文件上收到 404 错误。

服务器:Linux Ubuntu 18.04、nginx、DotNet

我有标准项目设置

启动.cs

        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }

程序.cs

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

        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseUrls("http://*:9580")
                .UseStartup<Startup>();
    }

加载资源失败:服务器响应状态为 404 ()

是我得到的错误,但在http://xxx.xxx.xxx.xxx上它工作正常。

标签: c#.netasp.net-core

解决方案


推荐阅读