欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

.Net Core + NGINX跳转登录时端口丢失

程序员文章站 2022-04-29 14:08:23
使用.Net Core + NGINX部署到服务器的时候,如果端口不是使用默认的80端口,在跳转到登录页面时,URL中的端口丢失。 ......

使用.Net Core + NGINX部署到服务器的时候,如果端口不是使用默认的80端口,在跳转到登录页面时,URL中的端口丢失。

NGINX的配置如下:

server {
    listen 8888;
    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;
    }
}

 

其实这并不是ASP.Net Core的问题,而是NGINX在返回跳转(302/301)时,没有把端口加入到“Location"中,所以只需要修改proxy_set_header,带上端口就可以了。

proxy_set_header Host $host:$server_port;

 

最后重启NGINX生效设置:

systemctl restart nginx

 

原文地址:https://www.zkea.net/codesnippet/detail/post-103.html