ubuntuにnginxサーバーを立てる
linux参考
nginxのインストール
aptでインストールすればOK
sudo apt update
sudo apt install nginx
ファイアウォールの設定
- ufwコマンドを使う
- Nginx HTTP or Nginx HTTPSをallowする
- OpenSSHもallowしとかないと、あとでsshできなくなるので注意
sudo ufw app list # Nginxのエントリがあることを確認
sudo ufw allow "Nginx HTTP"
sudo ufw allow "OpenSSH"
sudo ufw enable
sudo ufw status # 対象のエントリが活きていることを確認
nginxの設定ファイルの調整
inctoreは、適宜、ドメイン名に置き換える
- ファイル置き場の作成
/var/www/inctore/html - ファイルの作成
/var/www/inctore/html/index.html - 設定ファイルを作成
/etc/nginx/sites-available/inctoreファイルを作り、serverディレクティブを書く - 設定ファイルをリンク
/etc/nginx/sites-enabled/inctoreに、上のファイルのシンボリックリンクを置く /etc/nginx/nginx.confのserver_names_hash_bucket_size 64;を有効にするnginx -tで設定ファイルの文法チェックsystemctl restart nginxでnginx再起動
ここまでで、httpでアクセスできるはず
証明書のインストール
- snapでcertbotをインストールする
sudo snap install core; sudo snap refresh coresudo apt remove certbotsudo snap install --classic certbotsudo ln -s /snap/bin/certbot /usr/bin/certbot
- ファイアウォールの調整
sudo ufw delete allow 'Nginx HTTP'sudo ufw allow 'Nginx Full'
- certbotで証明書をインストール
sudo certbot --nginx -d viewer.inctore.com