Home  >  Article  >  Backend Development  >  nginx uses ssl module to configure HTTPS support, _PHP tutorial

nginx uses ssl module to configure HTTPS support, _PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:02:50924browse

nginx uses the ssl module to configure HTTPS support.

The ssl module is not installed by default. If you want to use this module, you need to specify the --with-http_ssl_module parameter at compile time. The installation module depends on the OpenSSL library and some reference files, which are usually not in the same package. Usually this file name is something like libssl-dev.

Generate certificate

You can generate a simple certificate by following these steps:
First, enter the directory where you want to create the certificate and private key, for example:

  1. $ cd /usr/local/nginx/conf

Create a server private key. The command will ask you to enter a password:

  1. $ openssl genrsa -des3 -out server.key 1024

Create Certificate for Signing Request (CSR):

  1. $ openssl req -new -key server.key -out server.csr

Remove the required password when loading Nginx with SSL support and using the above private key:

  1. $ cp server.key server.key.org
  2. $ openssl rsa -in server.key.org -out server.key

Configure nginx

Finally mark the certificate using the above private key and CSR:

  1. $ 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:

  1. server {
  2. server_name YOUR_DOMAINNAME_HERE;
  3. listen 443;
  4. ssl on;
  5. ssl_certificate /usr/local/nginx/conf/server.crt;
  6. ssl_certificate_key /usr/local/nginx/conf/server.key;
  7. }

Restart nginx.
This will allow access via:

https://YOUR_DOMAINNAME_HERE

You can also add the following code to redirect port 80 to 443IT People Paradise

  1. server {
  2. listen 80;
  3. server_name ww.centos.bz;
  4. rewrite ^(.*) https://$server_name$1 permanent;
  5. }

Please indicate the source of the article when reprinting: http://www.centos.bz/2011/12/nginx-ssl-https-support/

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084387.htmlTechArticlenginx uses the ssl module to configure HTTPS support. The ssl module is not installed by default. If you want to use this module You need to specify the with-http_ssl_module parameter when compiling. The installation module depends on...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn