nginx 配置 http重定向到https

话不多说直接代码

server {
    listen 80;
    server_name www.xxxxx.com;
    return 301 https://$server_name$request_uri;
}


server {
    listen 443 ssl;
    server_name www.xxxxx.com;

    ......

}

 

就这样配置就可以

详解一下

listen 80; - 使用端口80,服务器将侦听指定域名的所有传入连接。

server_name www.xxxxx.com - 它指定域名。因此,将其替换为您要重定向的网站域名。

return 301 https://$server_name$request_uri; - 将流量移至该站点的HTTPS版本。$request_uri变量用于完整的原始请求URI,其中也包含参数。

 

其他的已经不需要解释了吧,443代表监听https 请求。

 

posted @ 2022-08-12 15:17  深水是沉默  阅读(1095)  评论(0编辑  收藏  举报