Tutorials for deploying SSL certificates and redirecting to HTTPS under Nginx
Step 1: download the certificate file of Nginx version. After decompressing it, you can see a .key file and a .crt / .pem file.
Step 2: upload the certificate. Upload the above .key file and .crt / .pem file to the / root directory and name them ssl.crt/ssl.pem and ssl.key
Step 3: the Nginx of the LNMP one-click installation package is configured in the / usr/local/nginx/conf/vhost/ directory, and find the configuration file (such as anxinssl.com) of the corresponding site domain name. The Nginx configuration file for a normal installation is in / etc/nginx/nginx.conf. The vi command enters the modification.
Modify it to:
Server {
Listen 443
Change server_name anxinssl.com http://www.anxinssl.com;# to your domain name
Ssl on
Root html
Index index.html index.htm
Ssl_certificate / root/ssl.pem
Ssl_certificate_key / root/ssl.key
Ssl_session_timeout 5m
Ssl_ciphers ECDHEMUR AES128MUG GCMMuSHA256 Flex ECDHEVE ECDH Von AESHV Highi A null LV A null L RC4 A null L RC4
Ssl_protocols TLSv1 TLSv1.1 TLSv1.2
Ssl_prefer_server_ciphers on
Location / {
Root html
Index index.html index.htm
}
}
Step 4: set 301 to redirect to HTTPS
Server
{
Listen 80
Server_name anxinssl.com http://www.anxinssl.com; # changed to your domain name
Rewrite ^ / (. *) https://anxinssl.com/$1 permanent; # if your website has www, please add www before the domain name
}
Server
{
Listen 443
#. The remaining configurations are the same as above
}