Nginx uses SSL module to configure HTTPS support

Source: Internet
Author: User
Tags openssl library openssl rsa openssl x509 nginx server

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:

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

Create a server private key, and the command will let you enter a password:

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

Create a certificate (CSR) for the signing request:

    1. $ OpenSSL req-new-key server.key-out SERVER.CSR

Remove the required password when loading SSL-supported Nginx 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

The last token certificate uses the above private key and the 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:

    Server {        server_name your_domainname_here;         443 ;        SSL on;         /usr/local/nginx/conf/server.crt;         /usr/local/nginx/conf/server.key;    }

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

(. *) https://$server _name$1 Permanent;}
-------------------------------------------------------------------------------This article mainly introduces the method of configuring security certificate for Nginx server in Linux , share the specific installation steps under the certificate, a friend of the need to refer to the next

Share how I step-by-step to configure SSL on Nginx.
First, make sure that the OpenSSL library is installed and that the –with-http_ssl_module parameter is used when installing Nginx.

Beginner or rookie recommends using LNMP for one-click installation.

To generate a certificate:
Enter the directory where you want to generate the certificate
Cd/usr/local/nginx/conf

Create a server private key using OpenSSL and enter the information for the appropriate prompt

Copy CodeThe code is as follows:
OpenSSL genrsa-des3-out Server.key 1024

Create certificate signing requests (Certificate Signing request (CSR))

Copy CodeThe code is as follows:
OpenSSL Req-new-key server.key-out SERVER.CSR

Clear prompt must enter key when starting Nginx with SSL

Copy CodeThe code is as follows:
CP Server.key server.key.org
OpenSSL rsa-in server.key.org-out Server.key

Signing a certificate with a newly generated private key and CSR

Copy CodeThe code is as follows:
OpenSSL x509-req-days 365-in server.csr-signkey server.key-out server.crt

Configuration Description:
Join in Server

Copy CodeThe code is as follows:
SSL on;
SSL_CERTIFICATE/USR/LOCAL/NGINX/CONF/SERVER.CRT;
Ssl_certificate_key/usr/local/nginx/conf/server.key;

Set the listen port to 443 and start the test.

Nginx uses SSL module to configure HTTPS support

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.