1. 首先在你的 nginx 目录下创建一个.conf文件:

    1
    touch /etc/nginx/sites-available/test-https.conf

    并填入如下内容:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    server {
    listen 443 ssl;
    server_name www.example.com;
    index index.html;

    ssl_certificate /usr/local/nginx/cert/www.example.com.pem;
    ssl_certificate_key /usr/local/nginx/cert/www.example.com.key;

    location / {
    proxy_pass http://127.0.0.1:__YOUR_PORT__;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    }

    location ^~ /api/ {
    proxy_pass http://127.0.0.1:__YOUR_PORT__/;
    }
    }

    创建软连接到/etc/nginx/sites-available/test-https.conf

    1
    ln -s /etc/nginx/sites-available/test-https.conf /etc/nginx/sites-enabled/test-https.conf
  2. 将HTTPS证书上传到/usr/local/nginx/cert/

  3. 重启NGINX服务

    1
    systemctl restart nginx