By rakibtg
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.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hello,
I think that you would need to create a Docker Network and attach the 2 containers to that Network. That way you would be able to connect from container 1 to container 2 by name.
You could take a look at this answer here on how to do that:
Hope that this helps! Regards, Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.