#author("2020-04-27T09:24:01+09:00","","")
#author("2020-04-28T11:56:59+09:00","","")
#navi2(Raspberry Pi/Ubuntu Server/nginx,toc,prev,next)
----
#contents
----
* nginx SSL設定 (HTTPS設定) [#j2a40ca8]

** Let's Encrypt を用いた 証明書の生成 [#sbfe8557]
ドメインを取得している場合、Let's Encrypt を用いて、ブラウザ等にて警告がでない HTTPS 通信が可能です。
+インストール
 # apt install certbot
+ルータ等の設定を変更し、外部から HTTP, HTTPS にアクセスできる状態にする。
+nginxを一旦停止する。
 # service nginx stop
+証明書を生成する。
 # certbot certonly
+いくつか問われるので、適宜設定する。
 1: Spin up a temporary webserver (standalone)
 2: Place files in webroot directory (webroot)
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
certbot 用のサーバーを利用して証明書を生成するので''1 [Enter]'' を押下する。
 Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):
メールアドレスを入力する。
 Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
利用規約同意なので、内容を確認して、Agree を選択する。(A [Enter])
 Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.]
メール送ってよいか問われるので、Yes/No いずれかを入力する。
 Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel):
ドメイン名を入力します。(複数ある場合は、カンマかスペース区切りで入力します。)
生成に成功すると、証明書が保存された場所が表示されます。
通常 /etc/letsencrypt/live/[ドメイン名]/ 配下に、fullchain.pem, privkey.pem が生成されます。
** 証明書の生成 [#c5297f14]
[[Raspberry Pi/Ubuntu Server/証明書の生成]] の手順に従い、証明書を生成します。

** SSLの設定 [#n9feab55]
+下記コマンドにて default-ssl ファイルを生成する。
 # cp /etc/nginx/site-available/default /etc/nginx/site-available/default-ssl
+下記コマンドで、シンボリックリンクを生成する。
 # cd /etc/nginx/site-enabled/
 # ln -s /etc/nginx/site-available/default-ssl
+コピーしたdefault-sslファイルを元に、次のように編集する。
 server {
     # HTTPS のポート番号を listen する。
     listen 443 default_server;
     listen [::]:443 default_server;
 
     # SSLを有効にする。
     ssl on;
  
     # 証明書、プライベートキーを指定する。
     # ssl_certificate [証明書のパス];
     # ssl_certificate_key [プライベートキーのパス];
     ssl_certificate /etc/letsencrypt/live/ehobby.clear-net.jp/fullchain.pem;
     ssl_certificate_key /etc/letsencrypt/live/ehobby.clear-net.jp/privkey.pem;
 
     # ドキュメントルート
     root /var/www/html;
 
     # / 指定時に選択されるファイル
     index index.html index.htm index.php
 
     server_name _;
 
     location / {
         # First attempt to serve request as file, then
         # as directory, then fall back to displaying a 404.
         try_files $uri $uri/ =404;
     }
 }
** 設定反映(再起動) [#ha5c7d8e]
 # service nginx restart




----
#navi2(Raspberry Pi/Ubuntu Server/nginx,toc,prev,next)

トップ   一覧 検索 最終更新   ヘルプ   最終更新のRSS