I have the following docker-compose.yml files located in two different folders:
~/front/docker-compose.yml
and
~/api/docker-compose.yml
I need to connect proxy_server localhost:3000 (from frontend) to nginx config file (from api). What could I be missing?
Here is the ngix config file:
server {
listen 80;
index index.html;
server_name localhost;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html/public;
}
server {
listen 80; # the port nginx is listening on
server_name client.localhost; # setup your domain here
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1m;
proxy_connect_timeout 1m;
proxy_pass http://127.0.0.1:3000/; # set the address of the Node.js instance here
}
}
When I do docker-compose logs -f nginx
, this is the error:
2020/08/07 10:50:10 [error] 28#28: *9 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.16.1, server: client.localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3000/favicon.ico", host: "client.localhost", referrer: "http://client.localhost/"
error after running docker-compose logs -f nginx
Here is the front/docker-compose.yml:
version: "3.5"
services:
client:
build:
context: .
dockerfile: Dockerfile
container_name: client
ports:
- "3000:3000"
networks:
- client_esl
networks:
client_esl:
external:
name : nginx_esl
api/docker-compose.yml
version: "3.5"
networks:
esl:
services:
site:
image: nginx:stable-alpine
container_name: nginx
ports:
- "80:80"
volumes:
- ./src:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
networks:
- esl
Dockfile on front folder
FROM node:12.4-alpine
RUN mkdir -p /usr/src/nuxt-app
RUN WORKDIR /usr/src/nuxt-app
RUN apk update && apk upgrade
RUN apk add git
COPY . /usr/src/nuxt-app/
RUN npm install
RUN npm run build
EXPOSE 3000
ENV NUXT_HOST=0.0.0.0
ENV NUXT_PORT=3000
CMD [ "npm", "start" ]