The SSL module is not installed by default, and if you want to use the module, you will need to specify the –with-http_ssl_module parameter at compile time, and the installation module relies on the OpenSSL library and some reference files, usually not in the same package. Usually this file name is similar to Libssl-dev.
Generate certificate
You can generate a simple certificate by using the following steps:
First, go to the directory where you want to create the certificate and private key, for example:
- $ cd/data
Create a server private key, and the command will let you enter a password:
- $ OpenSSL genrsa-des3-out server.key 1024
Create a certificate (CSR) for the signing request:
- $ OpenSSL req-new-key server.key-out SERVER.CSR
Remove the required password when loading SSL-supported Nginx and using the above private key:
- $ CP Server.key server.key.org
- $ OpenSSL rsa-in server.key.org-out Server.key
Configure Nginx
The last token certificate uses the above private key and the CSR:
- $ OpenSSL x509-req-days 365-in server.csr-signkey server.key-out server.crt
Modify the Nginx configuration file to include the newly tagged certificate and private key:
server { listen 443; server_name localhost; root html; Index index.html index.htm; SSL on; SSL_CERTIFICATE/DATA/SERVER.CRT; Ssl_certificate_key/data/server.key; Ssl_session_timeout 5m; Ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2; Ssl_ciphers "high:!anull:! MD5 or high:!anull:! Md5:!3des "; Ssl_prefer_server_ciphers on; Location/{ try_files $uri $uri/=404; }}
Restart Nginx.
This can be accessed in the following ways:
Https://YOUR_DOMAINNAME_HERE
In addition, you can also add the following code to enable 80 port redirection to 443
server { listen; server_name ww.centos.bz; Rewrite ^ (. *) https://$server _name$1 permanent;}
Nginx uses SSL module to configure HTTPS support