LoginSignup
8

More than 5 years have passed since last update.

[さくらVPS]CentOS7にLet's EncryptのSSL証明書を導入する

Last updated at Posted at 2018-04-02

はじめに

さくらVPSを新しく借りたのでCentOS7 + nginxの環境で
Let's EncryptのSSL証明書を導入する。

環境

OS: CentOS Linux release 7.4
WebServer: nginx 1.13.9
DocumentRoot: /var/www/html
Domain: www.example.com

install

# cd /usr/local
# git clone https://github.com/certbot/certbot.git

証明書の取得

# cd certbot
# ./certbot-auto -n certonly --webroot -w /var/www/html -d www.example.com -m example@example.com --agree-tos

optionについて

1 2 3
certonly サブコマンド SSL/TLS サーバ証明書の取得のみを行う。
-n (--noninteractive) 一般オプション クライアントソフトウェアの実行時に、ユーザーからの入力を一切求めない。
-m --email 一般オプション トラブルや証明書の期限が近いなどの連絡先のメールアドレスを指定する。
-w (--webroot-path) プラグイン関係のオプション ドキュメントルートのパスを指定する。
-d (--domain) 一般オプション SSL/TLS サーバ証明書の取得を申請するドメイン名を指定する。
--webroot プラグイン関係のオプション ドキュメントルート以下に認証用ファイルを生成する。
--agree-tos 自動化オプション Let's Encrypt の利用規約に同意する。

Nginx(ついでにhttp2)

ついでにhttp2も(listenに「http2」を追加)

/etc/nginx/conf.d/ssl.conf
server {
    listen 443 ssl http2;
    server_name www.example.com;
    ssl_certificate     /etc/letsencrypt/live/www.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;
    root /var/www/html;

    location / {
        index index.php index.html index.htm;
    }

    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include       fastcgi_params;
    }
}

Port(443)の解放

portを解放していなければ解放する

# firewall-cmd --add-service=https --permanent
# systemctl restart firewalld

証明書の更新

# ./certbot-auto renew --webroot -w /var/www/html

ちなみに証明書の有効期限が近くないと
「Cert not yet due for renewal」
このようなメッセージが出て更新できない。

参考

Let's Encrypt 総合ポータル
CentOS7でLet's Encryptを使う
Let's Encrypt で Nginx にSSLを設定する

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8