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

第一、配置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;