LoginSignup
10
15

More than 3 years have passed since last update.

CentOS7 の Nginx で Let's Encrypt を使う

Last updated at Posted at 2019-05-03

CentOS 7.6 に Nginx をインストールして Let's Encrypt の設定をします。
abc.example.com に設定するとします。

1) http(80),https(443) のポートにアクセスできるようにします。

sudo firewall-cmd --permanent --add-service=http --zone=public
sudo firewall-cmd --permanent --add-service=https --zone=public
sudo firewall-cmd --reload

2) Nginx をインストールします。

sudo yum -y install nginx

設定ファイルは、
/etc/nginx/nginx.conf です。

root /usr/share/nginx/html;

root /var/www/html;
に変更しています。

3) Nginx の起動

sudo systemctl start nginx
sudo systemctl enable nginx

ブラウザーで、http://abc.example.com にアクセスします。

4) certbot のインストール

sudo yum -y install certbot

5) 証明書の生成

sudo certbot certonly --webroot -w /var/www/html -d abc.example.com --email aaa@example.com

6) /etc/nginx/nginx.conf の編集

/etc/nginx/nginx.conf
server {
listen  443 ssl;
server_name     abc.example.com;
ssl_certificate         /etc/letsencrypt/live/abc.example.com/fullchain.pem;
ssl_certificate_key     /etc/letsencrypt/live/abc.example.com/privkey.pem;
}

7) Nginx の再起動

sudo systemctl restart nginx

https://abc.example.com にブラウザーでアクセス

AWS などだと、OS の外でポートのアクセスに制限がかけることができるので、外部から 443 ポートにアクセスできるか確認します。

nmap -sT abc.example.com

次のように表示されれば、アクセスが出来ます。

PORT     STATE  SERVICE
80/tcp   open   http
443/tcp  open   https
10
15
0

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
10
15