2024-03-26
目录
Nginx http重定向到https
推荐做法:写一个 server 块,永久重定向到指定地址
server {
listen 80;
server_name solo.mengfei.icu;
return 301 https://$server_name$request_uri;
}
还有其他方式:判断域名进行跳转
server {
if ($host = solo.mengfei.icu) {
return 301 https://$host$request_uri;
}
}
变量说明
301 https://$server_name$request_uri;的整体意思是:当发生某种条件(这通常会在前面的配置行中定义,例如一个location块)时,服务器应该返回一个301永久重定向,告诉客户端应该使用HTTPS版本的相同URL(即相同的服务器名称和请求URI)来重新发送请求。
$server_name 是一个nginx变量,表示:当前请求的域名
$request_uri 是一额 nginx变量,标识:当前请求的 地址
子域名 www 没什么特殊的,只是大家比较习惯使用
标题:Nginx http重定向到https
作者:temp12138
地址:https://solo.mfyzl.icu/articles/2024/03/11/1710165587045.html
废话短说