nano docker-compose.yml
# docker-compose.yml
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
mkdir nginx
nano nginx.conf
# nginx.conf
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;
}
}
}
dockertest 폴더에 파일과 폴더를 만들고 위 예제를 입력해 준다
docker compose up -d
docker ps
compose up을 해주고 ps를 확인한다
docker exec -it 11-nginx-1 /bin/bash
nginx를 bash로 접속한다 (-it 옵션 뒤 이름은 ps목록에 NAMES 또는 container id를 쓴다)
cat /etc/nginx/nginx.conf
# nginx.conf
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;
}
우선 ngix.conf 파일을 찾아 열어보면 맨 아래 /etc/nginx/conf.d 경로에 파일이 있다고 한다
cat /etc/nginx/conf.d/default.conf
# default.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
위에서 찾은 경로에 default.conf 파일을 열어봤더니 이번엔 /usr/share/nginx/html 경로에 있다고 한다
위 경로로 이동해 폴더 안의 내용을 확인해 보니 이곳이 기본 폴더인 것 같다
mkdir blog
cat > blog/index.html
# index.html
hi
위 예제에서 nginx.conf파일에 적어둔 blog 폴더를 만들고 적당한 index파일을 만든 후
웹으로 접속해서 잘 접속되는지 확인한다
docker exec -it 11-apache-1 /bin/bash
nginx를 만들었으니 apache도 만들어주기 위해 같은 방법으로 접속한다
접속해서 목록을 확인하니 conf 폴더가 있다
cat conf/httpd.conf
# httpd.conf
############################################
# Do not add a slash at the end of the directory path. If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used. If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "/usr/local/apache2"
###########################################
우선 conf 폴더로 이동해 httpd.conf 파일을 살펴보니 server root가 보인다 처음 접속한 경로이다
이번에는 htdocs를 확인해 봤더니 index.html 파일이 보인다 이곳이 기본경로인 것 같다
mkdir community
cat > community/index.html
# index.html
hi
nginx때와 똑같이 예제에 적어둔 community 폴더를 만든 후 적당한 index.html 파일을 만든 다음 웹으로 접속해 본다
잘 접속되는 걸 확인할 수 있다
'Docker' 카테고리의 다른 글
docker commit (0) | 2023.10.06 |
---|---|
docker volume (0) | 2023.10.05 |
docker network (0) | 2023.10.05 |
docker compose를 활용한 wordpress 설치 (0) | 2023.10.05 |
docker, minikube 기초설정, 예제 (0) | 2023.10.04 |