nginx.conf を /etc/nginx/ 直下に配置
com.example.conf とかを /etc/nginx/conf.d/ 配下に配置
SSL 類の設定は任意の場所(/etc/nginx/ssl/ とか)に配置
MDN Observatoryで総合チェック
ImmuniWeb WebScanでもう少し詳しくチェック
CSP EvaluatorでCSPチェック
Report URIで設定のレポーティング
GTMetrixでパフォーマンスチェック
# 最新版Nginxをリポジトリに追加
curl http://nginx.org/keys/nginx_signing.key | sudo apt-key add -
VCNAME=`cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2` && sudo -E sh -c "echo \"deb http://nginx.org/packages/ubuntu/ $VCNAME nginx\" >> /etc/apt/sources.list"
VCNAME=`cat /etc/lsb-release | grep DISTRIB_CODENAME | cut -d= -f2` && sudo -E sh -c "echo \"deb-src http://nginx.org/packages/ubuntu/ $VCNAME nginx\" >> /etc/apt/sources.list"
# インストール
apt update && apt upgrade
apt install nginx
# 起動
service nginx start
service nginx status
# ulimit -n の値を65536にする(デフォルト 1024)
sudo vim /etc/security/limits.conf
### 以下を追記
root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536
###
# カーネルのパラメータチューニング
sudo vim /etc/sysctl.conf
### 以下を追記
net.core.somaxconn = 1024
net.core.netdev_max_backlog = 5000
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_wmem = 4096 12582912 16777216
net.ipv4.tcp_rmem = 4096 12582912 16777216
net.ipv4.tcp_max_syn_backlog = 8096
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 10240 65535
###
# 再起動して有効化
sudo reboot
# AppArmor (Ubuntu版SELinuxみたいなもの)のユーティリティをインストール
apt install apparmor apparmor-profiles apparmor-utils
# Nginx用の設定を作るためログをとる
cd /etc/apparmor.d/
aa-autodep nginx
aa-complain nginx
# Nginxの再起動
service nginx restart
# ログからNginxの許可設定を作成
aa-logprof
aa-enforce nginx
# AppArmorの有効化
service apparmor restart
service nginx restart
apparmor_status