Table of Contents
SSL Certificate Usage in Nginx Reverse Proxy
Use OpenSSL to generate an SSL certificate
Configuring SSL certificates in Nginx
SSL Certificate Monitoring
1. View the certificate expiration time
2. Nagios Monitoring
3. Let's Encrypt
Conclusion
Home Operation and Maintenance Nginx SSL certificate monitoring in Nginx reverse proxy

SSL certificate monitoring in Nginx reverse proxy

Jun 10, 2023 am 10:52 AM
nginx reverse proxy ssl certificate

Nginx is a high-performance web server and reverse proxy server. It is widely used in many large websites and applications because it is stable and reliable. The SSL (Secure Sockets Layer) certificate is a digital certificate used to securely transfer data between the client and the server. In Nginx, the use of SSL certificates is closely related to reverse proxy. This article will explore the use of SSL certificates in Nginx reverse proxy and its monitoring.

SSL Certificate Usage in Nginx Reverse Proxy

In Nginx, the reverse proxy server acts as a front-end server, receiving requests from clients and forwarding them to the back-end server. When Nginx acts as a reverse proxy server, it can also be used to encrypt and decrypt SSL connections, which requires the use of an SSL certificate.

In order to configure the SSL certificate in Nginx, we need to generate the SSL certificate first. Certificates can be generated using many different tools, including OpenSSL, ACME Client, and Certbot. Here we take using OpenSSL to generate a certificate as an example.

Use OpenSSL to generate an SSL certificate

Before using OpenSSL to generate an SSL certificate, we need to install OpenSSL on the server. We can use the following command to verify whether OpenSSL has been installed:

openssl version
Copy after login

If the version information of OpenSSL is returned, it means it has been installed. If it is not installed, you can install it through the following command:

sudo apt-get update
sudo apt-get install openssl
Copy after login

After the installation is completed, we can use the following command to generate the certificate:

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt
Copy after login

This command will generate a self-certificate valid for 365 days. Sign the SSL certificate and store it in the /etc/nginx/ssl directory. Among them, nginx.key is the private key file and nginx.crt is the certificate file.

Configuring SSL certificates in Nginx

Once the certificates are generated, they can be configured into Nginx. The following configuration can be added to the Nginx configuration file:

server {
  listen 443 ssl;
  server_name example.com;

  ssl_certificate /etc/nginx/ssl/nginx.crt;
  ssl_certificate_key /etc/nginx/ssl/nginx.key;

  location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    # This line enables HTTPS for the proxy
    proxy_ssl_verify                  on;
    proxy_ssl_certificate            /etc/nginx/ssl/nginx.crt;
    proxy_ssl_certificate_key        /etc/nginx/ssl/nginx.key;
    proxy_ssl_session_reuse          on;
  }
}
Copy after login

This configuration indicates that Nginx will listen for HTTPS connections on port 443 and use the generated SSL certificate to encrypt the connection. It also sets up a reverse proxy that forwards client requests to http://localhost:8000.

SSL Certificate Monitoring

The SSL certificate is valid for a limited time. Once a certificate expires, it is no longer valid, causing the website to become unsafe. Therefore, the SSL certificate used in the Nginx reverse proxy needs to be monitored to ensure the validity period of the certificate.

The following are some common methods of SSL certificate monitoring:

1. View the certificate expiration time

You can use the following command to view the expiration time of the SSL certificate:

echo | openssl s_client -servername example.com -connect example.com:443 2>/dev/null | openssl x509 -noout -dates
Copy after login

Where example.com is the domain name of your website. This command will output the start date and expiration date of the certificate.

2. Nagios Monitoring

Nagios is a comprehensive monitoring solution that helps you monitor servers, applications, and network services. It can also monitor the expiration time of SSL certificates. To use Nagios to monitor SSL certificates, you need to install Nagios and the SSL Certificate Monitoring plugin for Nagios.

3. Let's Encrypt

Let's Encrypt is a free SSL certificate authority that helps you easily configure SSL certificates for Nginx reverse proxy. Additionally, Let's Encrypt certificates are valid for 90 days, so you need to renew your certificate regularly.

In order to use Let's Encrypt to obtain an SSL certificate, you need to install Certbot. After installing Certbot, you can run the following command to obtain the certificate:

sudo certbot certonly --webroot -w /var/www/example.com -d example.com
Copy after login

Where, /var/www/example.com is the root directory of your website, and example.com is the domain name of your website. Certbot will automatically verify it on your server and issue you a certificate.

Conclusion

This article introduces the use and monitoring method of SSL certificate in Nginx reverse proxy. When using an SSL certificate, you must regularly check the certificate's expiration time. By automatically renewing certificates using Nagios monitoring or Let's Encrypt, you can ensure that your certificate is always valid. Monitoring SSL certificates is a key step in protecting your website and customer data.

The above is the detailed content of SSL certificate monitoring in Nginx reverse proxy. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

What to do if nginx server is hung What to do if nginx server is hung Apr 14, 2025 am 11:42 AM

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.

See all articles