apt install nginx
nano /etc/nginx/sites-available/image.rustk.com
添加以下配置:
server { listen 80; server_name image.rustk.com; location / { proxy_pass http://ip:8180; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
创建符号链接到 sites-enabled:
ln -s /etc/nginx/sites-available/image.rustk.com /etc/nginx/sites-enabled/
检查 Nginx 配置文件是否正确:
nginx -t
如果一切正常,重启 Nginx 服务:
systemctl restart nginx
安装 certbot 和 Nginx 插件:
apt update apt install certbot python3-certbot-nginx
获取 SSL 证书
certbot --nginx -d image.rustk.com
手动配置 Nginx (如果需要修改)
如果需要手动配置或调整 nginx.conf,可以参考以下配置文件示例:
server { listen 80; server_name image.rustk.com; return 301 https://$host$request_uri; # 自动重定向到 HTTPS } server { listen 443 ssl; server_name image.rustk.com; ssl_certificate /etc/letsencrypt/live/image.rustk.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/image.rustk.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers HIGH:!aNULL:!MD5; location / { proxy_pass http://ip:8180; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
检查 Nginx 配置
nginx -t
重启 Nginx
systemctl restart nginx
Let's Encrypt 证书通常有 90 天的有效期,certbot 会自动为你更新证书。不过,你可以通过以下命令手动测试自动更新是否工作正常:
certbot renew --dry-run
本文作者:rustk
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!