SoFunction
Updated on 2025-03-04

Specific steps for setting up HTTPS monitoring in Nginx

1. Obtain an SSL certificate

First, you need to obtain an SSL certificate, which can be obtained from the following channels:

  • Self-signed certificate (for testing)
  • Paid certificate (such as purchased certificate)

Here, the blogger uses this website to generate/certificate/apply

2. Install the certificate

Install the certificate file and private key to the server, usually.crtand.keydocument. Determine the directory to store by yourself.

3. Configure Nginx

Edit Nginx configuration files, according to your actual situation, usually in/etc/nginx/middle.

(1) Configure HTTP redirection to HTTPS

To redirect all HTTP requests to HTTPS, you can add the following code to the Nginx configuration file:

server {
    listen 80;
    server_name ;

    # Redirect all requests to HTTPS    return 301 https://$host$request_uri;
}

(2) Configure HTTPS server

In the same configuration file, add the configuration of the HTTPS server:

server {
    listen 443 ssl;
    server_name ;

    # SSL certificate path, fill in according to actual situation    ssl_certificate /xxx/your_domain.crt;
    ssl_certificate_key /xxx/your_domain.key;

    # Recommended SSL configuration    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    
    location / {
        # Configure your website root directory        root /var/www/your_domain;
        index  ;
    }

    # Proxy to other ports    #location / {

    #    proxy_pass http://127.0.0.1:8360;
    #}
}

4. Check and restart Nginx

Make sure the configuration file has no syntax errors:

sudo nginx -t

If there is no error, restart Nginx:

sudo systemctl restart nginx

5. Test

By visitandTest whether HTTP to HTTPS is implemented.

This way, you successfully configure Nginx to use HTTPS and redirect all HTTP requests to HTTPS.

This is the article about the specific steps of setting up HTTPS monitoring in Nginx. For more information about setting up HTTPS monitoring in Nginx, please search for my previous articles or continue browsing the following related articles. I hope everyone will support me in the future!