IT Trend

Docker Nginx 사용하는 방법

remake 2026. 8. 10. 22:04

Docker로 Nginx를 사용중이라면 명령어가 좀 다른데요

 

바로 docker exec nginx nginx -t 라고 명령어를 쳐야 합니다.

 

 

그리고 네트워크가 다르다면 네트워크를 연결도 시켜줘야 합니다.

 

안할경우 upstream이 에러 있다고 뜹니다.

ubuntu@-vm:~/docker/wordpress/nginx/conf.d$ sudo docker network connect pet_default nginx
ubuntu@-vm:~/docker/wordpress/nginx/conf.d$ sudo docker exec nginx nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
ubuntu@doru2-vm:~/docker/wordpress/nginx/conf.d$

 

그 다음 Docker NGINX의 ssl 폴더를 확인해야 함

 

sudo docker compose stop nginx

sudo certbot certonly \
  --standalone \
  --config-dir ./ssl \
  --work-dir ./ssl/work \
  --logs-dir ./ssl/logs \
  -d remake.kr

 

그리고 아래 명령어로 인증서를 받는다

 

sudo docker run --rm \
  -v /home/ubuntu/docker/wordpress/ssl:/etc/letsencrypt \
  -v /usr/share/nginx/html:/usr/share/nginx/html \
  certbot/certbot:latest \
  certonly \
  --webroot \
  -w /usr/share/nginx/html \
  -d auto.remake.kr

 

인증서가 잘 받아졌습니다.

server {
    listen 80;
    server_name remake.kr;

    location /.well-known/acme-challenge/ {
        root /usr/share/nginx/html;
    }


}

 

sudo docker compose exec nginx nginx -s reload