Skip to content

Instantly share code, notes, and snippets.

@wang-zhijun
Last active October 27, 2016 07:17
Show Gist options
  • Save wang-zhijun/48d34dc12ba9a27756d1e1ff93f58a44 to your computer and use it in GitHub Desktop.
Save wang-zhijun/48d34dc12ba9a27756d1e1ff93f58a44 to your computer and use it in GitHub Desktop.
Let's encrypt

Renew

30 2 * * 1 /usr/local/sbin/certbot-auto renew >> /var/log/le-renew.log


NginxにSSl証明書を適応させる

  • 証明書お生成
wget https://dl.eff.org/certbot-auto
chmod 0755 certbot-auto
./certbot-auto certonly --standalone -d domain.com
  • upstreamを使って、80番に来るリクエストあ全部443にリダイレクトする. /etc/nginx/nginx.conf設定ファイルお編集
http {
    
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  mydomain.com;
        # 80番に来るリクエストあ全部443にリダイレクトする
        return 301 https://$host$request_uri; 

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

    upstream cloud_storage {
        server 127.0.0.1:9000;
    }
    server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  mydomain.com;

        ssl_certificate "/etc/letsencrypt/live/mydomain.com/fullchain.pem";
        ssl_certificate_key "/etc/letsencrypt/live/mydomain.com/privkey.pem";
        
        location / {
            proxy_pass http://cloud_storage;
        }
        
    }
    ......
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment