
version: "3"
services:
nginxproxy:
image: nginx:1.18.0
ports:
- "80:80" # 변경
restart: always
volumes:
- "./nginx/nginx.conf:/etc/nginx/nginx.conf"
nginx:
depends_on:
- nginxproxy
image: nginx:1.18.0
restart: always
apache:
depends_on:
- nginxproxy
image: httpd:2.4.46
restart: always
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
upstream docker-nginx {
server nginx:80;
}
upstream docker-apache {
server apache:80;
}
server {
listen 80;
location /blog/ {
proxy_pass http://docker-nginx;
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-Host $server_name;
}
location /community/ {
proxy_pass http://docker-apache;
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-Host $server_name;
}
}
}
"/blog/" 경로로 들어오는 요청을 처리한다. 여기서는 "docker-nginx" 업스트림 서버로 프록시한다.
"/community/" 경로로 들어오는 요청을 처리한다. 여기서는 "docker-apache" 업스트림 서버로 프록시한다.
cf. 먼저 해당 nginx 컨테이너 실행 쉘을 실시킨다.
docker exec -it 04_nginx_proxy_path-nginx-1 /bin/bash
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf
}

NGINX TEST
~ 생략 ~
ServerRoot "/usr/local/apache2"
~ 생략 ~
Apache의 루트 디렉토리가 "/usr/local/apache2"임을 확인한다.
해당 아파치 서버 접속 시 /usr/local/apache2/htdocs/index.html 파일이 기본으로 열리게끔 설정되어 있다.
APACHE TEST