search
HomeOperation and MaintenanceNginxSSL certificate monitoring in Nginx reverse proxy

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

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

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

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;
  }
}

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

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

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
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
The Ultimate Showdown: NGINX vs. ApacheThe Ultimate Showdown: NGINX vs. ApacheApr 18, 2025 am 12:02 AM

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX in Action: Examples and Real-World ApplicationsNGINX in Action: Examples and Real-World ApplicationsApr 17, 2025 am 12:18 AM

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINX Unit: Supporting Different Programming LanguagesNGINX Unit: Supporting Different Programming LanguagesApr 16, 2025 am 12:15 AM

NGINXUnit supports multiple programming languages ​​and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

Choosing Between NGINX and Apache: The Right Fit for Your NeedsChoosing Between NGINX and Apache: The Right Fit for Your NeedsApr 15, 2025 am 12:04 AM

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.

How to start nginxHow to start nginxApr 14, 2025 pm 01:06 PM

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx

How to check whether nginx is startedHow to check whether nginx is startedApr 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 close nginxHow to close nginxApr 14, 2025 pm 01:00 PM

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

How to configure nginx in WindowsHow to configure nginx in WindowsApr 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.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.