购买阿里云的服务器

登录到服务器上ssh root@你的服务器ip

安装nginx

  1. 更新本地软件包索引:sudo apt update
  2. 安装nginx: sudo apt install -y nginx

安装https(如果不需要就不用走这一步)

  1. apt-get install python-software-properties apt-get install software-properties-common
  2. sudo add-apt-repository ppa:certbot/certbot
  3. sudo apt-get update
  4. sudo apt-get install -y certbot python3-certbot-nginx

生成证书

  1. 停掉nginx:service nginx stop
  2. 生成对应域名的证书:certbot certonly --standalone -d 你的域名(📢这里的域名需要解析到你当前的服务器上否则会报错)

配置nginx

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
29
30
31
server {
listen 80;
server_name 你的域名;
return 301 https://$server_name$request_uri;
}

server {
server_name www.ouyanting.com;
listen 443 ssl;
#listen [::]:443 ssl ipv6only=on;
ssl_certificate /etc/letsencrypt/live/你的域名/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/你的域名/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/你的域名/chain.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

root 你的域名需要访问的文件夹路径;

location / {
index index.html;

proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Server $host;
}

location ~ (.*\.html)/$ {
rewrite (.*\.html)/$ $1 permanent;
}
}

启动nginx

执行service nginx start