Nginx Configure SSL Certificate

Source: Internet
Author: User
Tags ssl certificate

All HTTP requests in the recent project have to be upgraded to HTTPS, and an SSL certificate with an Nginx configuration is practiced.

Since our certificate is issued by the company, the experience of applying for a certificate is omitted, and the application for free certificate can be searched by itself.

The certificate received is divided into two files, one is XXX.CRT, the other is Xxx.key, and the corresponding public and private keys are respectively.

Step1. Suppose our Nginx installation directory is:/usr/a/b/nginx/, go to the Conf directory below, create a new directory under the Conf directory, let's name Sslfile, and throw two certificate files into this directory.

Step2. Edit the Nginx.conf file in the Conf directory, and, of course, it's a good idea to back it up before editing. We found a section similar to the following:


Step3. If you just want your site to support HTTPS access, insert two lines below server_name to add two lines of content:

Listen 443;
SSL on;
Step4. If you want your site to be compatible with HTTP and HTTPS access, insert a line below server_name to add a line:

Listen 443 SSL
Step5. Insert three more lines and add content:

Ssl_certificate SSLFILE/XXX.CRT;
Ssl_certificate_key Sslfile/xxx.key;
Ssl_session_timeout 5m;

Step6. After editing is complete, save exit, go to directory/usr/a/b/nginx/sbin/, execute command nginx-t, test our modified configuration file syntax is correct, if correct will output the following prompt:


Step7. Then proceed to execute the command, Nginx-s reload, reload the configuration file. After execution, enter the HTTPS URL in the browser to access, if the address bar has a small lock on the flag, it proves the upgrade success, congratulate yourself.




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.