【问题标题】:ASP.NET behind nginx on linuxLinux 上 nginx 背后的 ASP.NET
【发布时间】:2021-03-12 06:27:10
【问题描述】:

我目前正在学习 ASP.NET,并在我的开发盒上发布了我的第一个应用程序。 现在我正试图把它放在 nginx 后面。

 location / {
    try_files $uri $uri/ @dotnet;
}
    location @dotnet {
            proxy_pass         http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
    }

但这会导致 403。在日志中它说目录列表是禁止的 /path/to/wwwroot/

目前我正在使用

    location / {
            proxy_pass         http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
    }

但这样一来,静态文件由 Kestrel 提供服务。

【问题讨论】:

    标签: asp.net linux nginx reverse-proxy


    【解决方案1】:

    以防万一其他人有这个问题,我是这样解决的:

        root /path/to/wwwroot;
    location / {
            try_files $uri @dotnet;
    }
        location @dotnet {
            proxy_pass         http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header   Upgrade $http_upgrade;
            proxy_set_header   Connection keep-alive;
            proxy_set_header   Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
        }
    

    替换 try_files $uri $uri/ @dotnet; 和 try_files $uri @dotnet;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-26
      • 1970-01-01
      • 2012-02-04
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多