LoginSignup
1
3

More than 5 years have passed since last update.

Let's Encryptを使ってSSL設定の覚書(ubuntu + nginx)

Last updated at Posted at 2018-07-05

はじめに

決済導入のためにサイトをSSL化した時の覚書です。

実装

1.nginxに設定する

https証明書を発行するとき、
http:///.well-known/acme-challenge/ にアクセスすることで認証を行うため、ここに設定を置いておかないと404エラーなどになってしまう。

/etc/nginx/conf.d/server.conf
server {
    ...

    location ^~ /.well-known/acme-challenge/ {
      default_type "text/plain";
      root /usr/share/nginx/html;
    }

1.443ポートを通す

$ sudo ufw allow 443

2.証明書をとる

git clone https://github.com/letsencrypt/letsencrypt.git
cd letsencrypt
$ ./letsencrypt-auto certonly --webroot -w /usr/share/nginx/html -d hoge.com

3.確認する

$ sudo ls /etc/letsencrypt/live/hoge.com

>この下にpemが配置
cert.pem  chain.pem  fullchain.pem  privkey.pem  README
/etc/nginx/conf.d/server.conf
server {
    listen 443;
    ....
    ssl on;
    ssl_certificate /etc/letsencrypt/live/hoge.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/hoge.com/privkey.pem;

5.httpもhttpsにredirectしておく

/etc/nginx/conf.d/server.conf
server {
    listen 80;
    server_name hoge.com;
    #return 301 https://hoge.com;
    return 301 https://$host$request_uri;
}

6.localで起動する場合、thinを使うと便利。

$ gem install thin
$ bundle exec thin start --ssl -p 3001

https://localhost:3001
1
3
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
1
3