在 Ngnix 中隱藏連接埠並顯示網站鏈接

在 Ngnix 中隱藏連接埠並顯示網站鏈接

我已經嘗試過以下提到的建議:

Nginx 反向代理重新導向中隱藏連接埠

但這對我沒有幫助。

我已經為我的 django+gunicorn 應用程式完成了 nginx 反向代理,並且它在連接埠 8000 上開啟。http://some_machine:8000查看我的應用程式正在運行。我已經使用 Nginx 反向代理程式映射了在該機器上運行的 localhost 和機器名稱。我想隱藏端口,並且在 url 中想要類似的內容http://some_machine/zmk代替http://some_machine:8000/zmk

我正在將以下內容寫入我的/etc/nginx/conf.d資料夾:

upstream zms {    
  ip_hash;    
  server zms:8000;    
}

# portal

server {    
  location /zmk {    
        proxy_pass http://zms/;    
        # proxy_redirect http://some-machine:8000/ http://some-machine/zmk;    
        port_in_redirect off;    
        # autoindex on;            
        proxy_set_header Host $host:$server_port;    
        proxy_set_header X-Real-IP $remote_addr;    
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;    
        proxy_set_header   X-Forwarded-Proto $scheme;    
    }
  listen 8000;    
  server_name localhost    
  server_name_in_redirect off;    
}

我不明白我做錯了什麼?我也嘗試將上述內容複製到/etc/nginx/site-available資料夾中。

答案1

將您的listen陳述更改listen 80為。這樣你的 nginx 伺服器將監聽連接埠 80 並將流量代理到連接埠 8000。

相關內容