【问题标题】:Hosting a mvc net core in root and the staging version in a subdirectory using nginx使用 nginx 在根目录中托管 mvc 网络核心并在子目录中托管暂存版本
【发布时间】:2019-12-05 20:04:54
【问题描述】:

这个想法是在网站根目录中提供生产 mvc net core 应用程序,并在子目录中提供暂存版本:

目前nginx中的配置是这样的:

upstream myapp{
        server localhost:5000;
    }

upstream premyapp{
    server localhost:6000;
}

server {
    listen *:80;
    add_header Strict-Transport-Security max-age=15768000;
    return 301 https://$host$request_uri;
}

server {
    listen *:443    ssl;
    server_name my.website.com;
    ssl_certificate /home/vhost/ssl/myapp.crt;
    ssl_certificate_key  /home/vhost/ssl/myapp-decrypted.key;
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_ecdh_curve secp384r1;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on; #ensure your cert is capable
    ssl_stapling_verify on; #ensure your cert is capable

    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;

    location / {
        proxy_pass  http://myapp;
    }

    location /pre {
        proxy_pass  http://premyapp;
    }
}

startup.cs文件中的配置有这样的配置:

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        ...

        if (env.IsStaging())
        {
            app.UseStaticFiles("/pre");
            app.UsePathBase("/pre");
        }
        else app.UseStaticFiles();

       ...
     }

但它不起作用,生产应用程序不会重定向到任何控制器,并且暂存应用程序不会加载静态文件。

有什么想法吗?

【问题讨论】:

    标签: c# asp.net-mvc nginx .net-core nginx-config


    【解决方案1】:

    问题出在静态文件配置中,现在是:

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            ...
    
            if (env.IsStaging())
            {
                app.UsePathBase("/pre");
                app.UseStaticFiles();
            }
    
           ...
         }
    

    它成功了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-28
      • 2012-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多