[英]simple nginx reverse proxy not working in docker compose
fhsmgr 代理在/但不能在任何其他位置使用 404
fhsdir 代理在 /dir 處提供 404,但當我在 localhost:5000 上直接瀏覽到它時,我得到了預期的 output,因此主機已啟動並正在運行。 此外,nginx 不會像我以前看到的那樣抱怨無效的主機和退出。
proxy_redirect off;
也是。似乎它唯一能讓我代理的是'/',雖然我知道我已經在類似的設置中代理到不同位置路徑的其他服務器。
-- docker 組成
version: "3.7"
services:
fhsmgr:
build: fhsmgr
restart: always
fhsdir:
build: fhsdir
restart: always
ports:
- 5000:5000
nginx:
build: nginx
restart: always
ports:
- 80:80
environment:
- NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
- FHSMGR_HOST=fhsmgr
- FHSMGR_PORT=5000
- FHSDIR_HOST=fhsdir
- FHSDIR_PORT=5000
-- nginx 配置
events {}
http {
# upstream fhsmgr {
# server ${FHSMGR_HOST}:${FHSMGR_PORT};
# }
# upstream fhsdir {
# server ${FHSDIR_HOST}:${FHSDIR_PORT};
# }
# a simple reverse-proxy
server {
listen 80 default_server;
location / {
proxy_pass http://fhsmgr:5000;
proxy_redirect off;
}
location /dir {
proxy_pass http://fhsdir:5000;
proxy_redirect off;
}
}
}
我正在修改這個項目https://github.com/AwsGeek/lightsail-containers-nginx以使其適用於我的用例。 還沒有到lightsail,只是使用docker在本地撰寫
你錯過了 docker-compose 中的container_name
,試試這個
version: "3.7"
services:
fhsmgr:
build: fhsmgr
restart: always
container_name: fhsmgr # allow other containers to access by container_name
fhsdir:
build: fhsdir
restart: always
container_name: fhsdir
ports:
- 5000:5000
nginx:
build: nginx
restart: always
ports:
- 80:80
environment:
- NGINX_ENVSUBST_OUTPUT_DIR=/etc/nginx
- FHSMGR_HOST=fhsmgr
- FHSMGR_PORT=5000
- FHSDIR_HOST=fhsdir
- FHSDIR_PORT=5000
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.