AR ホームベーカリー

オイラのアウトプット用ホームベーカリー!

nginx:latest の config 中身が知りたかった

fargate 用に雑に書いたコンフィグを /etc/nginx/conf.d/ 以下に放り込んでいたんだけど、「これデフォルトのファイルどうなってんだ?」 という疑問がシュッと出てきたので確認してみた (DockerHub のリポジトリページ見てたけど、それっぽい記述が見当たらなかった)。

hub.docker.com

ちなみにビルドを 2022/12/13 頃に実施していたはずなので、ファイル一覧の日付や latest で参照されるバージョンもそのあたりになっている。

ので、そういうものだと思って未来で見ている人は勘弁してほしい。

確認した方法

test-nginx という名前で build した後、 run 実行時に bash を付与してログインして確認した。

docker build -t test-nginx -f ./docker/Dockerfile .
docker run -it test-nginx /bin/bash
./docker/Dockerfile
FROM nginx:latest

ディレクトリ構成

/etc/nginx/ 以下は、このようになっている。

drwxr-xr-x 1 root root 4.0K Dec 21 11:28 .
drwxr-xr-x 1 root root 4.0K Jan  4 04:37 ..
drwxr-xr-x 1 root root 4.0K Dec 23 13:11 conf.d
-rw-r--r-- 1 root root 1007 Dec 13 15:53 fastcgi_params
-rw-r--r-- 1 root root 5.3K Dec 13 15:53 mime.types
lrwxrwxrwx 1 root root   22 Dec 13 17:26 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root  648 Dec 13 17:26 nginx.conf
-rw-r--r-- 1 root root  636 Dec 13 15:53 scgi_params
-rw-r--r-- 1 root root  664 Dec 13 15:53 uwsgi_params

ディレクトリは conf.d のみ。 で、そのディレクトリ内部はこう。

drwxr-xr-x 1 root root 4.0K Dec 23 13:11 .
drwxr-xr-x 1 root root 4.0K Dec 21 11:28 ..
-rw-r--r-- 1 root root 1.1K Dec 13 17:26 default.conf

各 conf ファイルについて

/etc/nginx/nginx.conf の後に、/etc/nginx/conf.d/default.conf が include される。 だいたい標準的なコンフィグですね。

/etc/nginx/nginx.conf
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
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;
}
/etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #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;
    #}
}

これらを踏まえて

Dockerfile を以下のようにして、 conf.d/default.conf は見ないようにしてしまうかー、という感じだった。

# 偉大なる元イメージ
FROM nginx:latest

# タイムゾーン
ENV TZ Asia/Tokyo

# 既存のコンフィグは不要なので消す
RUN rm -f /etc/nginx/nginx.conf

# コンフィグをコピーする
COPY nginx.conf /etc/nginx/nginx.conf

# 外部公開するポート
EXPOSE 80

# Nginx の制御
CMD ["nginx", "-g", "daemon off;"]