.Net Core + NGINX跳轉登錄時端口丟失


使用.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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM