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>

おすすめ記事