Home > Backend Development > PHP Tutorial > nginx uses ssl module to configure HTTPS support

nginx uses ssl module to configure HTTPS support

WBOY
Release: 2016-07-29 09:09:20
Original
1022 people have browsed it

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 the OpenSSL library and some reference files. Usually these files are not in the same software package. . Usually this file name is something like libssl-dev.

Generate Certificate

You can generate a simple certificate by following these steps:
First, go to 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 a 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 use the above private key:

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

Configure nginx

Finally sign 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.                                                                                            on;
  4. ssl_certificate /usr/local/nginx/conf/server.crt;
  5. ssl_certificate_key /usr/local/nginx/conf/server.key;
  6. }
Restart nginx. In this way, you can access it through the following methods:


https://YOUR_DOMAINNAME_HERE

In addition, you can also add the following code to redirect port 80 to 443IT People Paradise

server {

  1. listen 80;
  2. server_name ww.centos .bz;
  3. rewrite ^(.*) https://$server_name$1 permanent;
  4. }
Please indicate the source of the article when reprinting: http://www.centos.bz/2011/12/nginx- ssl-https-support/

The above introduces how nginx uses the ssl module to configure HTTPS support, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template