: This article describes how to configure HTTPS support for nginx using the ssl module. For more information about PHP tutorials, see. By default, the ssl module is not installed. to use this module, you need to specify the-with-http_ssl_module parameter during compilation. the installation module depends on the OpenSSL library and some reference files, these files are usually not in the same software package. Generally, this file name is similar to libssl-dev.
Generate certificate
To generate a simple certificate, follow these steps:
First, go to the directory where you want to create the certificate and private key, for example:
- $ Cd/usr/local/nginx/conf
Create a server private key. the command will allow you to enter a password:
- $ Openssl genrsa-des3-out server. key 1024
Create a CSR for the signature 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
Finally, mark the certificate with the above private key and CSR:
- $ Openssl x509-req-days 365-in server. csr-signkey server. key-out server. crt
Modify the Nginx configuration file to include the newly marked certificate and private key:
- Server {
- Server_name YOUR_DOMAINNAME_HERE;
- Listen 443;
- Ssl on;
- Ssl_certificate/usr/local/nginx/conf/server. crt;
- Ssl_certificate_key/usr/local/nginx/conf/server. key;
- }
Restart nginx.
In this way, you can access:
Https: // YOUR_DOMAINNAME_HERE
You can also add the following code to redirect port 80 to the 443IT paradise.
- Server {
- Listen 80;
- Server_name ww. centos. bz;
- Rewrite ^ (. *) https: // $ server_name $1 permanent;
- }
Reprinted please indicate the source of the article: http://www.centos.bz/2011/12/nginx-ssl-https-support/
The above section describes how to configure HTTPS support using the ssl module of nginx, including some content, and hope to help anyone interested in the PHP Tutorial.