1, install Certbot (for automatic renewal certificate)
# Add Installation source sudo add-apt-repository ppa:certbot/certbot# update apt installation source sudo apt-get update# installation sudoinstall Python-certbot-apache
2. Install Letsencrypt and generate certificates
# Install Letsencrypt sudo Install --agree-tos--email [email protected]163. com--webroot-w /var/html/www- Www.gabin.top-d Cab.gabin.top
--agree-tos--email [email protected]163. com-d www.gabin.top
3, check/etc/letsencrypt/live/www.gabin.top
Directory, the certificate file has been generated
- CERT.PEM: You don't have to care (this is actually a server certificate file)
- CHAIN.PEM: You don't have to care (this is actually ...) Read the documentation yourself, I didn't understand. It seems to be a chained certificate for recursive lookup)
- Fullchain.pem:cert.pem + CHAIN.PEM. Need to be configured in the Nginx configuration file
ssl_certificate .
- PRIVKEY.PEM: Private key. Need to be configured in the Nginx configuration file
ssl_certificate_key .
4. Configure Nginx Server
1) Modify the default service configuration
server { a; # Listen [::]:+; 301 301 https://}
2) Add an SSL site configuration
Vim/etc/nginx/sites-available/default-ssl
The following content:
Server {Listen443SSL HTTP2; # Listen [::]:443SSL HTTP2; server_name www.gabin.top; Location/{root/usr/share/nginx/html; Index index.html index.htm; } #error_page404/404. html; # REDIRECT Server error pages to the static page/50x.html # Error_page - 502 503 504/50x.html; Location= /50x.html {root/usr/share/nginx/html; } # Certs sent to the clientinchSERVER HELLO is concatenatedinchssl_certificate ssl_certificate/etc/letsencrypt/live/www.gabin.top/Fullchain.pem; Ssl_certificate_key/etc/letsencrypt/live/www.gabin.top/Privkey.pem; Ssl_session_timeout 1d; Ssl_session_cache shared:ssl:50m; Ssl_session_tickets off; # diffie-hellman parameter forDHE Ciphersuites, recommended2048Bits # Ssl_dhparam/etc/ssl/certs/Dhparam.pem; # Intermediate configuration. Tweak to your needs. Ssl_protocols TLSv1 TLSv1.1TLSv1.2; Ssl_ciphers'ecdhe-ecdsa-chacha20-poly1305:ecdhe-rsa-chacha20-poly1305:ecdhe-ecdsa-aes128-gcm-sha256: Ecdhe-rsa-aes128-gcm-sha256:ecdhe-ecdsa-aes256-gcm-sha384:ecdhe-rsa-aes256-gcm-sha384:d HE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256: ecdhe-ecdsa-aes128-sha:ecdhe-rsa-aes256-sha384:ecdhe-rsa-aes128-sha:ecdhe-ecdsa-aes256-sha384: Ecdhe-ecdsa-aes256-sha:ecdhe-rsa-aes256-sha:dhe-rsa-aes128-sha256:dhe-rsa-aes128-sha:dhe-rsa-aes256-sha256:d HE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256: aes256-gcm-sha384:aes128-sha256:aes256-sha256:aes128-sha:aes256-sha:des-cbc3-sha:! DSS'; Ssl_prefer_server_ciphers on; # HSTS (Ngx_http_headers_module is required) (15768000seconds =6months) Add_header Strict-transport-security max-age=15768000; # OCSP Stapling---# Fetch OCSP records from URLinchssl_certificate and cache them ssl_stapling on; Ssl_stapling_verify on; # # Verify chain of trust of OCSP response using Root CA and intermediate certs # Ssl_trusted_certificate/etc/letsencrypt/live/www.gabin.top/root_ca_cert_plus_intermediates; # resolver8.8.8.8 8.8.4.4Valid=300s; # Resolver_timeout 5s;}
3) Establish a soft connection and restart Nginx
# Create a soft link configuration site sudo Ln -s/etc/nginx/sites-available/default-ssl/etc/nginx/sites-sites-enabled# restart Nginx server sudo Service Nginx Restart
5. Regular Renewal Certificate
-E
Edit Add Task
2 Point Renewal: 2 * * * letsencrypt renew# Restart Nginx to make the certificate effective 3 * * * nginx-s Reload
Ubuntu generate HTTPS certificate for Let's encrypt