본문 바로가기
에러 디버그 기록

nginx: [emerg] "user" directive is not allowed here in /etc/nginx/conf.d/nginx.conf:1

by jphwany 2022. 10. 11.

nginx 이미지를 베이스로 가져오게 되면 docker 안쪽의 /etc/nginx/  경로에 
기본적으로 nginx.conf 파일이 존재한다 (docker run -it server_nginx sh )

이걸 에디터로 열어서 확인해보면,

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
}


여러 기본 설정 값이 작성되어 있고
마지막에 include /etc/nginx/conf.d/*.conf;  가 작성되어 있는걸 볼 수 있는데
/etc/nginx/conf.d/  경로에 있는, 내가 작성한 .conf 파일을 가져온다는 의미

그러니까 지금 저기 기본으로 설정되어 있는 값 + 내가 작성한 값이 합쳐진다고 할 수 있다
한마디로 중복이 되면 안된다는 것

내가 작성한 Dockerfile-nginx 를 보면,


docker 바깥에서 만든 nginx.conf 파일을 
docker 안쪽의 /etc/nginx/conf.d  경로로 복사하겠다고 작성한 것임을 알 수 있다

docker 바깥에서 만든 nginx.conf 파일과 
docker 안쪽에서 만든 /etc/nginx/conf.d  에 있는 파일이 중복 값이 존재해선 안되기 때문에

실제로 리버스 프록시 설정과 업스트림 설정한 값만 존재하면 된다



댓글