Nginx 도커화 포트 전달

Nginx 도커화 포트 전달

내 로컬 컴퓨터에 nginx가 있고 모든 http 트래픽을 리디렉션합니다.포트 80~8008이 간단한 구성을 사용하면 다음과 같습니다.

server {

    listen 8008;

#        location some-location {
#        
#        }

    location / {
        proxy_pass http://localhost:80/index.php/;
        proxy_set_header  X-Real-IP  $remote_addr;
    }
}

로컬에서는 모든 것이 잘 작동하지만 nginx를 docker 컨테이너에 배치하고 싶습니다. 내 Dockerfile:

FROM nginx

COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 8008 80

하지만 cmd로 이미지를 실행하면

docker run -d -p 8008:80 <image ID>

아무 일도 일어나지 않고 컨테이너가 중지됩니다. 로그는 여기에 있습니다:

docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2f2602efc455 a58e81b31db6 "nginx -g 'daemon of…" 10 seconds ago Exited (1) 10 seconds ago unruffled_galileo 


docker logs
2018/01/03 12:17:08 [emerg] 1#1: "server" directive is not allowed here in /etc/nginx/nginx.conf:1 nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:1

내가 뭘 잘못했나요?

답변1

좋아, 마침내 내 nginx.conf에서 오류를 발견했습니다: user nginx;worker process 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;
    keepalive_timeout  65;

      server {

        location / {
            proxy_pass http://localhost:80/index.php/;
            proxy_set_header  X-Real-IP  $remote_addr;
                   }
             }
}

도커파일:

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 8008

다음 명령을 사용하여 이미지를 시작합니다.

docker run -d -p 8008:80 <ID>

관련 정보