
ほとんどタイトルオンリー。普通に
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;
}
}
}
以上。