[英]Forward nginx 8080 port to 80
我有一個帶有多個 nginx 實例的服務器
其中一個運行在 8080
server {
listen 8080;
server_name myip v2.example.com www.v2.example.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://v2.example.com:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
但我想使用 example.com 進入站點,而不是 example.com:8080 問題是在端口 80 上運行了另一台服務器,我試圖用代理通行證修復它,但它似乎不起作用
我該如何解決?
您可以嘗試使用 ssl 端口443
。 當然,您可能需要添加有效的 ssl 證書以避免來自瀏覽器的錯誤消息。
如果您不想使用上述方法,則可以在其他實例之一上使用代理傳遞,如下所示:
location /some-url/ {
proxy_pass http://localhost:8080/;
}
之后,您可以通過以下方式訪問它:http://localhost:80/some-url/
使用return
重定向。 您可以將以下內容放在一個文件中:
server {
listen 80;
listen [::]:80;
server_name v2.example.com www.v2.example.com;
return 301 http://$host$request_uri:8080;
}
server {
listen 8080;
server_name myip v2.example.com www.v2.example.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.