Home > Operation and Maintenance > Windows Operation and Maintenance > How to install Nginx SSL certificate

How to install Nginx SSL certificate

不言
Release: 2019-03-30 16:12:23
Original
3367 people have browsed it

All sites running with SSL use the https protocol on the default port 443. SSL provides secure data communication by encrypting data between the server and client. This article will introduce configuring SSL in nginx server.

How to install Nginx SSL certificate

Step 1: Install nginx web server

We assume that nginx is already installed on the system, but if it is not installed yet, Please use the following commands to install.

$ sudo apt-get install nginx
Copy after login

Step 2: Obtain an SSL Certificate

For creating an SSL certificate, the first requirement is to create a private key and CSR. A CSR is a file that contains all the details about a domain, including the public key. First create a directory where you create the CSR and key.

# mkdir /etc/nginx/ssl/
# cd /etc/nginx/ssl/
Copy after login

Now create the CSR and key files using the following commands. Change the file names example.com.key and example.com.csr according to your domain name. This command will ask for information about your domain.

# openssl req -new -newkey rsa:2048 -nodes -keyoutexample.com.key-outexample.com.csr
Copy after login

After creating the CSR, request an SSL certificate from any certificate provider (such as geotrust, comodo, digicert or godaddy, etc.). After obtaining the certificate from the CA, merge the primary and intermediate certificate files into one file.

# cat example.com.crt DigiCertCA.crt >> example.com.pem
Copy after login

Step 3: Set up virtual host with SSL

Let us edit the nginx configuration file /etc/nginx/conf.d/example.com.conf and add the following value.

# HTTPS Server Block

server {

    listen   443;
    server_name example.com www.example.com;

    root /var/www/xyz.com/httpdocs;
    index index.html index.htm;

    ssl on;
    ssl_certificate /etc/nginx/ssl/example.com.pem;
    ssl_certificate_key /etc/nginx/ssl/example.com.key;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    ssl_prefer_server_ciphers on;
}
Copy after login

Step 4: Restart nginx

Finally, restart the nginx server for the changes to take effect.

# service nginx restart
Copy after login

The above is the detailed content of How to install Nginx SSL certificate. For more information, please follow other related articles on the PHP Chinese website!

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