

























首先,你需要获取一个 SSL 证书,可以从以下渠道获得:
这里,博主使用这个网站生成 https://ssl.host.mw/certificate/apply
安装证书文件和私钥到服务器,通常是 .crt 和 .key 文件。自己确定存放的目录。
编辑 Nginx 配置文件,按照自己实际情况来,通常在 /etc/nginx/nginx.conf 中。
将所有 HTTP 请求重定向到 HTTPS,你可以在 Nginx 配置文件中添加以下代码:
server {
listen 80;
server_name www.liuzijian.com;
# 重定向所有请求到 HTTPS
return 301 https://$host$request_uri;
}在同一个配置文件中,添加 HTTPS 服务器的配置:
server {
listen 443 ssl;
server_name www.liuzijian.com;
# SSL 证书路径,按照实际情况填写
ssl_certificate /xxx/your_domain.crt;
ssl_certificate_key /xxx/your_domain.key;
# 推荐的 SSL 配置
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
location / {
# 配置你的网站根目录
root /var/www/your_domain;
index index.html index.htm;
}
# 代理到其他端口
#location / {
# proxy_pass http://127.0.0.1:8360;
#}
}确保配置文件没有语法错误:
sudo nginx -t如果没有错误,重启 Nginx:
sudo systemctl restart nginx通过访问 http://www.liuzijian.com 和 https://www.liuzijian.com 测试是否实现了 HTTP 到 HTTPS 的重定向。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。