Мне нужно настроить проксирование между контейнерами docker. В моем вариации контейнера доступны с хостовой машины, но друг друга не видят. Что я делаю неправильно? Как правильно?
version: "2.4"
services:
nginx:
image: nginx:1.17.2-alpine
container_name: nginx
volumes:
- ./default.nginx:/etc/nginx/conf.d/default.conf
ports:
- 8989:8989
frontend:
container_name: frontend
environment:
- VIRTUAL_HOST=localhost:3000
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- 3000:3000
backend:
container_name: backend
environment:
- VIRTUAL_HOST=localhost:1337
build:
context: ./backend
dockerfile: Dockerfile
ports:
- 1337:1337
front
FROM keymetrics/pm2:latest-alpine
ENV NPM_CONFIG_LOGLEVEL error
WORKDIR /usr/src/app
RUN apk update && apk upgrade && apk add --no-cache bash git openssh
RUN apk --no-cache add curl
COPY . .
RUN yarn install
RUN yarn build:ssr
EXPOSE 3000 1337
CMD [ "pm2-runtime", "start", "pm2.json" ]</blockquote>
back
<blockquote>FROM strapi/base:latest
RUN yarn global add strapi
RUN mkdir /srv/app && chown 1000:1000 -R /srv/app
RUN apk --no-cache add curl
WORKDIR /srv/app
EXPOSE 1337 3000
COPY . .
RUN yarn
# CMD ["strapi", "develop"]
CMD ["strapi", "start"]
default.nginx
server {
listen 8989;
server_name localhost;
location / {
proxy_pass http://frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location localhost:3000 {
proxy_pass http://frontend:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location localhost:3000/graphql {
proxy_pass http://backend:1337/graphql;
# proxy_pass http://backend:1337;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location ^~/graphql {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Frame-Options SAMEORIGIN;
# proxy_pass http://backend:1337/graphql;
proxy_pass http://localhost:1337/graphql;
}
location localhost:1337 {
proxy_pass http://backend:1337;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# location ~ /\.ht {
# deny all;
# }
}