
다음 파일이 있습니다 docker-compose.yml
.
version: '3'
services:
server:
build:
context: ../../
dockerfile: ./packages/website/Dockerfile
command: node /cutting/index.js
environment:
PORT: 8000
NODE_ENV: production
restart: always
nginx:
build:
context: ./
dockerfile: ./nginx/Dockerfile
command: tail -f /dev/null
depends_on:
- server
ports:
- "8000:8000"
restart: always
그리고 다음은 nginx.conf
:
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/logs/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
include mime.types;
default_type application/octet-stream;
access_log /tmp/logs/nginx.access.log combined;
sendfile on;
server {
proxy_http_version 1.1; # this is essential for chunked responses to work
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
client_max_body_size 4G;
server_name frontend;
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types application/javascript text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
keepalive_timeout 5;
location /static/ {
alias /static/;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# UNCOMMENT LINE BELOW IF THIS IS BEHIND A SSL PROXY
#proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
proxy_pass http://localhost:8000;
}
}
}
이것이 2개의 컨테이너를 생성하는 경우 nginx가 다른 컨테이너에서 localhost:8000을 볼 수 있도록 하려면 어떻게 해야 합니까?
답변1
name
에서 정의한 대로 컨테이너를 사용합니다 docker-compose.yml
. Docker는 각 컨테이너 내의 DNS를 통해 명명된 컨테이너에 대한 IP 주소를 제공하고 컨테이너가 업데이트되면 이를 업데이트합니다.
이 경우에는 이를 호출했으므로 server
이를 사용하게 됩니다.
proxy_pass http://server:8000;
선적 서류 비치:Compose의 네트워킹
답변2
이 경우 다음과 같은 업스트림을 사용해야 합니다.
upstream backend {
server express-server:81; #you container/service name
}
그런 다음 다음을 사용하십시오.
proxy_pass http://backend