[英]Running Nginx behind Traefik, problem with ports different than 80
我想使用 Docker (docker-compose) 在 Traefik 反向代理后面運行 Nginx 作為 static 文件服務器。
docker-compose.yml
version: '3.8'
services:
traefik:
image: traefik
command:
- --entrypoints.web.address=:80
- --providers.docker
- --providers.docker.exposedbydefault=false
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
nginx:
build: ./docker/dev/nginx/.
labels:
- traefik.enable=true
- traefik.http.routers.nginx.entrypoints=web
- traefik.http.routers.nginx.rule=PathPrefix(`/static`) || PathPrefix(`/media`) || Path(`/robots.txt`) || Path(`/favicon.ico`)
- traefik.http.services.nginx.loadbalancer.server.port=80
nginx.conf
server {
listen 80;
listen [::]:80;
...
}
它可以工作,但是當我嘗試將內部 nginx 端口更改為另一個端口時,比如說 8082,Traefik 返回 502 錯誤並打印'502 Bad Gateway' caused by: dial tcp 172.21.0.6:8082: connect: connection refused"
.
通過更改端口,我的意思是:
traefik.http.services.nginx.loadbalancer.server.port=80
with traefik.http.services.nginx.loadbalancer.server.port=8082
in docker-compose.ymllisten 80; listen [::]:80;
listen 80; listen [::]:80;
用listen 8082; listen [::]:8082;
listen 8082; listen [::]:8082;
在 nginx.conf我在配置中有其他應用程序,例如在 gunicorn 服務器上運行的 Django。 gunicorn 監聽 3000 端口沒有問題,Traefik 將傳入的:80 請求轉發到:3000。 為什么它不適用於 nginx?
您已經告訴 nginx 監聽 8082 端口,這沒問題,但容器必須公開該端口。 (我猜默認容器會暴露 80 端口)
您似乎有一個自定義的 nginx 圖像,因此您可以在圖像中添加/替換EXPOSE關鍵字以獲得如下內容: EXPOSE 8082
。
您必須構建並重新啟動容器才能使更改生效,然后您可以使用docker-compose ps
檢查暴露的端口。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.