悪霊にさいなまれる世界 -The Demon-Haunted World

30代独身機械系技術者が雑記/セキュリティ/資産運用なんかを書きます/PGP・GPG Key:BC884A1C8202081B19A7A9B8AB8B419682B02FF8

RaspberryPi 3Bにdockerでnginxをインストールして良い感じのdocker-compose.ymlを作った

エンジンつながりで適当なエンジン画像。初見ではエンジンエックスなんて絶対読めない。wkpdより https://commons.wikimedia.org/wiki/File:Nissan_RB26DETT_Engine_-_Front_Side.jpg

ほとんどタイトルオンリー。普通に

docker pull nginx

でプルしたのはいいが、検索したところ丁度良いdocker-compose.ymlが無かったので自作した。引っかかったところも含めてもメモしておく。

/home/pi以下に/nginxディレクトリを作り、その中でさらにボリュームとしてマウントするconfigディレクトリとhtmlディレクトリを作る。

sudo mkdir nginx
cd nginx
sudo mkdir config
sudo mkdir html

nginxディレクトリにいれるdocker-compose.ymlは以下の通り。ログが溜まりすぎないように最大10MBで3ファイルのローテートするように設定した。

services:
  nginx:
    image: nginx:latest
    container_name: nginx
    ports:
      - "80:80"
    restart: always
    volumes:
      - /home/pi/nginx/html:/usr/share/nginx/html
      - /home/pi/nginx/config:/etc/nginx
    logging:
      driver: "json-file" # defaults if not specified
      options:
        max-size: "10m"
        max-file: "3"

なお/nginx/config/ディレクトリにnginx.confファイルがないとエラーが出る(ここでハマった)ので最低限度作ってやる。RaspberryPi3Bを想定しているのでwoker_processesはコア数と同じ4にした。

worker_processes 4;

events {
    worker_connections 1024;
}

http {
    server {
		# 80番ポート(http)でリクエストを受け付ける
    listen       80;
		# ドメイン名の指定
    server_name  localhost;

    location / {
        # リクエストされた際にドキュメントがある場所を指定
        root   /usr/share/nginx/html;
        # リクエストを受けた際に提供するファイル名
        index  index.html index.htm;
    }

    # エラーコードが発生した際に表示するURIの指定
    error_page   500 502 503 504  /50x.html;
    # "/50x.html"ページへ内部リダイレクト
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
	}
}

以上。