几个在Nginx环境中实现HTTP跳转HTTPS的方法

如今我们普遍的网站会用到HTTPS加密网址的,所以考虑到SEO的唯一性,我们需要将HTTP强制跳转到HTTPS,那应该如何实现呢?当然如果我们的WEB环境有自带的就不需要调整,如果没有自带则需要设置。这里有几个方法可用。

第一、配置Nginx文件

/etc/nginx/conf.d/nginx.conf

我们可以在这里修改。

    if ($scheme = http ) {
    return 301 https://$host$request_uri;
    }

或者:

    server_name www.itbulu.com;
    return 301 https://$server_name$request_uri;

第二、伪静态设置

我们也可以在伪静态文件中设置。

server_name www.itbulu.com ;
rewrite ^(.*) https://$host$1 permanent;

或者:

server_name www.itbulu.com ;
rewrite ^(.*) https://www.itbulu.com$1 permanent;
投上你的一票

原创文章,转载请注明出处:https://www.itbulu.com/nginx-redirect-https.html

上一篇 2024年9月12日 09:11
下一篇 2024年9月13日 14:30