⚓️ nginx
参考
TLS 证书
使用 certbot 申请 letsencrypt (CA) 颁发的证书, 通过 certbot-dns-cloudflare 自动续期
-
下载
Bash 1sudo apt install certbot python3-certbot-dns-cloudflare -
配置
Bash 1 2
echo "dns_cloudflare_api_token = API" > ~/.cloudflare.ini && \ chmod 600 ~/.cloudflare.ini -
申请
Bash 1 2 3 4 5 6 7 8
certbot certonly \ --register-unsafely-without-email \ --dns-cloudflare \ --dns-cloudflare-credentials ~/.cloudflare.ini \ --config-dir ~/letsencrypt/config \ --work-dir ~/letsencrypt/work \ --logs-dir ~/letsencrypt/logs \ -d dxlcq.cn -
查看
Bash 1 2 3 4
certbot certificates \ --config-dir ~/letsencrypt/config \ --work-dir ~/letsencrypt/work \ --logs-dir ~/letsencrypt/logs
安装及使用
-
安装
Bash 1sudo apt install nginx -
卸载
Bash 1 2
sudo apt purge nginx nginx-common sudo apt autoremove -
热重载
Bash 1sudo nginx -s reload -
重启服务
Bash 1sudo systemctl restart nginx
/etc/nginx/nginx.conf
- 主配置文件:用于定义全局配置和基本设置
- 包含指令:包含服务器级别的设置、全局变量、工作进程数、日志文件位置、用户权限、加载模块等
- 包含其他文件:通常会使用include指令将其他配置文件包含进来,如/etc/nginx/conf.d/*.conf,从而组织和管理配置文件
/etc/nginx/conf.d/*.conf
- 虚拟主机配置文件:用于定义具体的虚拟主机(服务器)配置的文件,通常用于设置特定域名的服务器块
- 作用范围:这个文件主要包含HTTP服务器块(server block),定义了具体的域名、监听端口、根目录、日志路径、反向代理设置等
- 从属关系:这个文件通常被主配置文件 nginx.conf 通过 include 指令包含进来,使得Nginx能够加载这些虚拟主机配置
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 | |
SSL 证书
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
-
安装
certbotBash 1 2
sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot -
首次申请
Bash 1sudo certbot certonly --webroot -w / -d dxlcq.cn -
测试更新
Bash 1sudo certbot renew --dry-run -
每周更新
sudo crontab -eBash 10 0 * * 1 certbot renew && nginx -s reload -
查看证书剩余时长
Bash 1sudo certbot certificates
下载站点与加密
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
使用 docker 快速部署 Nginx
| Bash | |
|---|---|
1 2 | |
反向代理
| Text Only | |
|---|---|
1 2 3 4 5 6 7 8 9 | |