官方nginx 模板

安装nginx及证书

#更新软件源
apt update

apt install wget curl sudo vim git -y  # Debian系统比较干净,安装常用的软件

#启用 BBR TCP 拥塞控制算法(直接复制下面)
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p

或者用这个脚本:
wget -O box.sh https://raw.githubusercontent.com/BlueSkyXN/SKY-BOX/main/box.sh && chmod +x box.sh && clear && ./box.sh


#安装nginx
apt install nginx
#安装acme:
curl https://get.acme.sh | sh
#添加软链接:
ln -s  /root/.acme.sh/acme.sh /usr/local/bin/acme.sh
#切换CA机构: 
acme.sh --set-default-ca --server letsencrypt
#申请证书:(域名用一二级都可以,我用的二级) 
acme.sh  --issue -d 你的域名 -k ec-256 --webroot  /var/www/html
#安装证书:
acme.sh --install-cert -d 你的域名 --ecc --key-file       /root/ssl/自己改.key  --fullchain-file /root/ssl/自己改.crt --reloadcmd     "systemctl force-reload nginx"

#强制证书更新
acme.sh --renew -d xxx.aprilowo.top --force
在执行
acme.sh --install-cert -d 你的域名 --ecc --key-file       /root/ssl/自己改.key  --fullchain-file /root/ssl/自己改.crt --reloadcmd     "systemctl force-reload nginx"
最后
systemctl reload nginx



你可以手动更新证书,但是如果时间还没到你需要加上 --force 参数

命令:

--renew 或 -r :更新证书
对应参数:

--domain 或 -d :指定域名

--force :强制更新

# 更新证书
shell> acme.sh --renew -d dnomd343.top --force
Renew: 'dnomd343.top'
···
Cert success.
···
Your cert is in  /home/dnomd343/.acme.sh/dnomd343.top/dnomd343.top.cer
Your cert key is in  /home/dnomd343/.acme.sh/dnomd343.top/dnomd343.top.key
The intermediate CA cert is in  /home/dnomd343/.acme.sh/dnomd343.top/ca.cer
And the full chain certs is there:  /home/dnomd343/.acme.sh/dnomd343.top/fullchain.cer

###用于从acme.sh中移除该证书,但并不吊销该证书
命令:
--remove :移除证书
对应参数:
--domain 或 -d :指定域名
# 移除证书
shell> acme.sh --remove -d dnomd343.top
dnomd343.top is removed, the key and cert files are in /home/dnomd343/.acme.sh/dnomd343.top
You can remove them by yourself.
执行证书移除命令后,acme.sh仅不再参与该证书的工作,但证书文件仍然在 ~/acme.sh 文件夹下,需要用户手动删除。

配置nginx.conf

step 1:在nginx.conf文件所在目录新建conf.d目录,即mkdir conf.d,为确保权限能够访问到

cd /etc/nginxchmod 777 conf.d
现在,就可以在 conf.d/下自定义 *.conf文件了

systemctl reload nginx