Question
pass_proxy not listening to containers using nginx in docker
I’m preparing a docker based dev environment for node and nginx but for some reason the nginx pass_proxy
is not pointing to the container using their service name.
Here are the configuration files:
default.conf
server {
listen 80;
error_log /var/log/nginx/error.log;
location /api {
proxy_pass http://web:3000;
}
}
nginx Dockerfile
FROM nginx:1.17-alpine
COPY ./default.conf /etc/nginx/conf.d/default.conf
CMD ["/bin/sh", "-c", "exec nginx -g 'daemon off;'"]
docker-compose.yml
version: '3.3'
services:
web:
build: ../backend
container_name: backend
restart: always
volumes:
- ../backend:/usr/src/app
- /usr/src/app/node_modules
ports:
- 6060:3000
server:
build: .
restart: always
container_name: nginx_server
volumes:
- ./log-nginx:/var/log/nginx/
depends_on:
- web
ports:
- 6000:80
I have exposed the web
as well and it works when i visit localhost:6060
but if i go to the nginx endpoint by going to this address localhost:6000/api
it shows an error page in the browser:
This site can’t be reached
Note that in the default.conf
file i have tried using different variations for the pass_proxy
container name, for example:
proxy_pass http://web;
proxy_pass http://web:3000;
proxy_pass web:3000;
proxy_pass web;
but it seems like non of them are working for nginx to shine. The logs file of nginx are also empty! what I might be missing here? Any help would be really helpful :)
One more thing, I am using the alpine based official images.
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×