我有一個類似的端點https://app1.company.com:5555,并且希望能夠使用所有頁面的 url 中的埠號瀏覽網站,并且還能夠在沒有埠號的情況下瀏覽,比如說另一個 server_namehttps://dev-app1.company.com
例如https://app1.company.com:5555/tag/general,https://dev-app1.company.com/categories/ulmighty應該都可以作業
每當埠存在時,如何讓 nginx 重定向并保留埠名稱?
目前有這個
server {
listen 80;
server_name dev-app1.company.com app1.company.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name dev-app1.company.com app1.company.com;
location ^~ / {
rewrite ^/(.*)$ /$1 break;
proxy_pass http://localhost:9090;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
但問題是它不使用埠號重定向,我希望它能夠使用 url 中的埠號重定向,只要服務在該埠上運行并且它正在5555埠上運行
更新:
應用程式已經在偵聽埠 5555,我可以在此處訪問https://app1.company.com:5555
當我有這個
server {
listen 80;
server_name app1.company.com;
return 301 https://app1.company.com:5555$request_uri;
}
但現在我想添加更多服務器名稱,這樣我也可以訪問其他沒有埠的服務器名稱
uj5u.com熱心網友回復:
能夠通過為標準和非標準埠添加額外的服務器塊來解決此問題
所以這是最終設定
server {
listen 80;
server_name dev-app1.company.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name dev-app1.company.com;
location ^~ / {
rewrite ^/(.*)$ /$1 break;
proxy_pass http://localhost:9090;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
server {
listen 80;
server_name app1.company.com;
return 301 https://app1.company.com:5555$request_uri;
}
server {
listen 443 ssl;
server_name app1.company.com;
location ^~ / {
rewrite ^/(.*)$ /$1 break;
proxy_pass http://localhost:9090;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/526952.html
上一篇:不能在同一個nginxconf檔案中用X-Frame-Options""覆寫X-Frame-Options"SAMEORIGIN"
下一篇:如何根據R中另一列中的值增加新列
