原文地址:https://itxiaozhang.com/aliyun-ecs-https-deployment-notes/
如果您需要远程电脑维修或者编程开发,请加我微信咨询。

一、服务器与环境准备

1
2
3
4
5
6
7
8
ssh root@<your-server>   # 登录服务器

sudo apt update && sudo apt upgrade -y
sudo apt install nginx -y

sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable

二、上传网页与证书

1. 新建目录

1
2
sudo mkdir -p /var/www/html
sudo mkdir -p /etc/nginx/ssl

2. 上传文件

  • 使用 WindTerm 上传网页文件到 /var/www/html/

  • 使用 WindTerm 上传证书文件到 /etc/nginx/ssl/

    • 24xiu.cn.pem
    • 24xiu.cn.key

3. 设置权限

1
sudo chmod 600 /etc/nginx/ssl/*

三、配置 Nginx

1
2
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak
sudo vim /etc/nginx/sites-available/default

配置内容:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# HTTP → HTTPS
server {
    listen 80;
    server_name 24xiu.cn www.24xiu.cn;
    return 301 https://$host$request_uri;
}

# HTTPS 配置
server {
    listen 443 ssl http2;
    server_name 24xiu.cn www.24xiu.cn;

    ssl_certificate /etc/nginx/ssl/24xiu.cn.pem;
    ssl_certificate_key /etc/nginx/ssl/24xiu.cn.key;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    root /var/www/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

四、验证

1
2
3
sudo nginx -t
sudo systemctl restart nginx
curl -I https://24xiu.cn

五、常见排查要点

  1. Nginx 状态

    1
    2
    
    sudo nginx -t
    systemctl status nginx
    
  2. 证书有效性

    1
    
    openssl x509 -in /etc/nginx/ssl/24xiu.cn.pem -noout -dates
    
  3. 安全组 确认放行:

    • TCP 22
    • TCP 80
    • TCP 443

六、后续维护

  • 证书到期后,在阿里云控制台续签并下载新证书(本次过期时间:2025-11-24)
  • 覆盖 /etc/nginx/ssl/24xiu.cn.pem/etc/nginx/ssl/24xiu.cn.key
  • 重启 Nginx sudo systemctl restart nginx

视频版本