Debian11上安装Nginx并配置HTTPS
Xplorist Lv6

Debian11上安装Nginx并配置HTTPS

reference-site-list

steps

安装Nginx

1
2
3
4
5
6
apt-get update

apt-get install nginx

systemctl enable nginx

使用acme进行HTTPS配置

  1. 向阿里云获取AccessKey

阿里云获取AccessKey

  1. 使用acme申请证书
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
cd /etc/nginx
mkdir cert.d
cd cert.d
mkdir xplorist.tech

cd /data

curl https://get.acme.sh | sh

vi ~/.bashrc
# 在.bashrc 里添加
## 编辑.bashrc开始
export Ali_Key="AccessKeyId"
export Ali_Secret="AccessKeySecret"
## 编辑.bashrc结束

source ~/.bashrc

acme.sh --issue --dns dns_ali -d xplorist.tech -d *.xplorist.tech --server letsencrypt

# 查看计划表
crontab -l

# 分配给 nginx
acme.sh --issue --dns dns_ali -d xplorist.tech -d *.xplorist.tech \
--server letsencrypt \
--installcert \
--key-file /etc/nginx/cert.d/xplorist.tech/key.pem \
--fullchain-file /etc/nginx/cert.d/xplorist.tech/full.pem \
--reloadcmd "nginx -s reload"

配置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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
vi /etc/nginx/nginx.conf

## nginx.conf开始

# 注释掉下行
#include /etc/nginx/sites-enabled/*;

## nginx.conf结束

vi /etc/nginx/conf.d/xplorist.tech.conf

# 新增xplorist.tech.conf
## xplorist.tech.conf编辑开始
# /etc/nginx/conf.d/xplorist.tech.conf
server {
listen 80;
server_name xplorist.tech;
client_max_body_size 1024m;

#80跳转到443
rewrite ^(.*)$ https://${server_name}$1 permanent;

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}

server {
listen 443 ssl http2;
server_name xplorist.tech;
client_max_body_size 1024m;

ssl_certificate /etc/nginx/cert.d/xplorist.tech/full.pem;
ssl_certificate_key /etc/nginx/cert.d/xplorist.tech/key.pem;

ssl_session_timeout 5m;

#开启HSTS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384;
#适时移除TLSv1.2
ssl_protocols TLSv1.3 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;

location / {
root /usr/share/nginx/html;
index index.html index.htm index.php;
}

location ~ \.php$ {
root /usr/share/nginx/html;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
}
## xplorist.tech.conf编辑结束

 评论