ベースイメージから、Nginx用クローンイメージの作成
# machinectl clone raspbian-buster-base pi-home-admin
コンテナを起動(-p でポートマッピングを行う)
# systemd-nspawn --bind=/var/cache/apt --network-bridge=br0 -bD /var/lib/machines/pi-home-admin -p443
ホスト名の変更
# echo pi-home-admin > /etc/hostname
IPアドレスの修正(Address を修正)
# vi /etc/systemd/network/host0.network
nginx, php-fpm のインストールと起動
# apt-get update # apt-get -y install nginx # apt-get -y install php7.3 php7.3-fpm php7.3-mbstring php7.3-mysqlnd php7.3-gd # systemctl enable nginx # systemctl start nginx # systemctl enable php7.3-fpm # systemctl start php7.3-fpm
オレオレ証明書の作成
# mkdir /var/lib/machines/pi-home-admin/etc/nginx/ssl # cd /var/lib/machines/pi-home-admin/etc/nginx/ssl # openssl genrsa 2048 > server.key # openssl req -new -key server.key > server.csr # openssl x509 -days 3650 -req -signkey server.key < server.csr > server.crt # rm server.csr # chmod 400 server.*
default 設定の削除
# cd /etc/nginx/ # mv sites-available/default sites-available/default.org # rm sites-enabled/default
server { listen 443 ssl; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; server_name localhost; root /var/www-ssl; index index.php index.html index.htm; location / { location ~* \.php$ { fastcgi_pass unix:/run/php/php7.3-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } }
Nginx のリロード
# systemctl reload nginx
# apt-get -y install phpmyadmin # mv /etc/phpmyadmin/config.inc.php /etc/phpmyadmin/config.inc.php.org # cp /usr/share/phpmyadmin/config.sample.inc.php /etc/phpmyadmin/config.inc.php
DBサーバー設定
/* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'cookie'; /* Server parameters */ $cfg['Servers'][$i]['host'] = '10.0.0.31'; $cfg['Servers'][$i]['connect_type'] = 'tcp'; $cfg['Servers'][$i]['compress'] = false; $cfg['Servers'][$i]['AllowNoPassword'] = false;
Basic 認証用のアカウントを作成
初めてパスワードを作る場合は、htpasswd -c と -c を付けて新規作成
# apt-get -y install apache2-utils # htpasswd /etc/nginx/.htpasswd ユーザ名 New password: パスワード Re-type new password: パスワード Adding password for user ユーザ名
Nginx 設定
# phpMyAdmin location /phpmyadmin { root /usr/share/; index index.php; auth_basic "Restricted"; auth_basic_user_file /etc/nginx/.htpasswd; location ~ ^/phpmyadmin/(.+\.php)$ { fastcgi_pass unix:/run/php/php7.3-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }