Home > Operation and Maintenance > Nginx > Configure secure SSL certificate transport in Nginx

Configure secure SSL certificate transport in Nginx

WBOY
Release: 2023-06-10 19:10:38
Original
1894 people have browsed it

With the popularity of the Internet, network security has become an important topic that people are paying more and more attention to. SSL certificate is one of the effective means to ensure website security. As a popular web server software, Nginx supports the SSL protocol. You can configure an SSL certificate to ensure the security of the website communication process. This article will describe in detail how to configure secure SSL certificate transmission in Nginx.

1. Obtain the SSL certificate

Before configuring the SSL certificate, you first need to obtain the certificate. Generally speaking, SSL certificates can be purchased from a certificate authority or generated yourself. Purchasing an SSL certificate gives you a more trusted certificate, but it comes with a fee. Self-generated certificates can be used for free, but the security is relatively low. This article uses Let's Encrypt as an example to introduce how to obtain an SSL certificate.

  1. Install the Certbot tool

Certbot is an automated SSL certificate management tool that can automatically obtain and configure SSL certificates. The method to install Certbot in Linux system is as follows:

On Ubuntu:

sudo apt-get install certbot python3-certbot-nginx
Copy after login

On CentOS:

sudo yum install certbot python3-certbot-nginx
Copy after login
  1. Get the SSL certificate

Certbot supports automatically executing the task of obtaining an SSL certificate. You only need to execute the following command:

sudo certbot --nginx -d example.com
Copy after login

Among them, the -d parameter is followed by the domain name for which the SSL certificate needs to be obtained. Certbot will automatically detect the Nginx configuration file and set up the SSL certificate without manually modifying the Nginx configuration file.

2. Configure Nginx to enable SSL

After obtaining the SSL certificate, you need to enable SSL in Nginx. The configuration method is as follows:

  1. Modify the Nginx configuration file

Open the Nginx configuration file nginx.conf, find the http block, and add the following content:

http {
    #其他http配置

    server {
        listen 443 ssl;
        server_name example.com;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

        #其他配置
    }
}
Copy after login

Among them, listen 443 ssl means listening to HTTPS requests, server_name configures the domain name to be listened to, ssl_certificate specifies the public key of the SSL certificate, and ssl_certificate_key specifies the private key of the SSL certificate.

  1. Restart Nginx

After the configuration is completed, you need to restart the Nginx service.

On Ubuntu:

sudo service nginx restart
Copy after login

On CentOS:

sudo systemctl restart nginx
Copy after login

3. Optimize SSL configuration

In addition to configuring the SSL certificate, there are some other Security measures can enhance the security of SSL. For example, disabling insecure protocols, cipher suites, etc. can be configured in the Nginx configuration file.

Here are some common SSL configuration optimizations:

  1. Disable SSLv2 and SSLv3: SSLv2 and SSLv3 have been proven to be insecure and should be disabled. Add the following code to the Nginx configuration file:
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
Copy after login
  1. Use a strong cipher suite: Using a stronger cipher suite can improve the security of SSL. Add the following code to the Nginx configuration file:
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256;
Copy after login
  1. Enable OCSP Stapling: OCSP Stapling can reduce network latency during the SSL handshake and improve SSL performance and security. Add the following code to the Nginx configuration file:
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 10s;
Copy after login

4. Test SSL security

After completing the SSL configuration, you can use the online SSL security testing tool to test the SSL security Perform testing to ensure configuration is correct and secure. It is recommended to use the online testing tool provided by Qualys SSL Labs, which can comprehensively test the security of HTTPS servers.

Through the above steps, you have successfully configured secure SSL certificate transmission in Nginx, making your website more secure and trustworthy. At the same time, it is also crucial to continuously update SSL configuration strategies and strengthen SSL security. I hope readers can become more and more confident on the road to protecting the security of their own websites.

The above is the detailed content of Configure secure SSL certificate transport in Nginx. 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