I would like to create two services, both of them having their own nginx. I would like to use third nginx as a reverse proxy to these two but I got
502 Bad Gateway
when I request
http://127.0.0.1:8080/ http://127.0.0.1:8080/one http://127.0.0.1:8080/two
accessing:
http://127.0.0.1:8081 http://127.0.0.1:8082
works ok
I have this docker-compose.yml
version: "3.3" services: nginx-one: image: nginx:1.17.8 ports: - "8081:80" networks: - frontend - backend volumes: - ./nginx-one/html:/usr/share/nginx/html nginx-two: image: nginx:1.17.8 ports: - "8082:80" networks: - frontend - backend volumes: - ./nginx-two/html:/usr/share/nginx/html nginx-reverse-proxy: image: nginx:1.17.8 ports: - "8080:80" networks: - frontend - backend volumes: - ./nginx-reverse-proxy/html:/usr/share/nginx/html - ./conf.d:/etc/nginx/conf.d networks: frontend: internal: false backend: internal: true
and dir structure
. ├── docker-compose.yml ├── nginx-one │ └── html │ └── index.html ├── nginx-reverse-proxy │ ├── conf.d │ │ └── default.conf │ └── html │ └── index.html ├── nginx-two └── html └── index.html
nginx.conf content
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; }
and
conf.d/default.conf
server { listen 80; location /one { proxy_pass http://127.0.0.1:8081/; } location /two { proxy_pass http://127.0.0.1:8082/; } }
When I comment this line of docker-compose.yml
# ./nginx-reverse-proxy/conf.d:/etc/nginx/conf.d
so conf.d/default.conf
is not used, requesting:
http://127.0.0.1:8080/
gives a proper response from the nginx-reverse-proxy itself but obviously
http://127.0.0.1:8080/one http://127.0.0.1:8080/two
don't provide any response from
http://127.0.0.1:8081 http://127.0.0.1:8082
but 404 instead.
https://stackoverflow.com/questions/65907904/nginx-reverse-proxy-to-other-nginx-502-bad-gateway January 27, 2021 at 03:23AM
没有评论:
发表评论