安装好Nginx之后,halo.conf文件配置如下:
server {
listen 80;
server_name xxx.com
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8090/;
}
}
之后配置SSL成功,可以成功以xxx.com访问博客,浏览器地址栏为https://xxx.com。
因为一开始没有配置server name为
server_name xxx.com www.xxx.com;
此时地址栏输入www.xxx.com为跳转到nginx欢迎页面:
我想要输入www.xxx.com和xxx.com一样的效果,都能跳转到博客首页,于是把经过ssl认证之后的halo.conf修改如下:
server {
server_name xxx.com www.xxx.com;
client_max_body_size 1024m;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://IP地址:8090/;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/xxx.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/xxx.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}server {
if ($host = xxx.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name xxx.com www.xxx.com;
client_max_body_size 1024m;
return 404; # managed by Certbot
}
重启nginx之后,xxx.com可以正常访问,地址栏显示https://xxx.com,正常跳转到博客首页
但是地址栏输入www.xxx.com时还是没有成功跳转到博客首页,这时也不跳转到nginx欢迎页了,而是直接 404 Not Found。
halo.conf还有要修改的吗?还是说不能这样做,必须重新全部认证一遍?