Nginx网站启用SSL后,强制http转移到https访问的方法

原先是http访问的网站,成功安装配置SSL后,https和http访问同时存在,这时就需要将所有http访问的链接全部301转移到https访问。

Nginx只需修改
YourDomain.conf 文件,添加如下代码,将http的80端口访问301到https即可:

if ($server_port = 80 ) {
return 301 https://$host$request_uri;
}

列子:

server
    {
        listen 80;
        #listen [::]:80;
        server_name YourDomain.com;
        index index.html index.htm index.php;
        root  /home/wwwroot/YourDomain.com;

	if ($server_port = 80 ) {
        return 301 https://$host$request_uri;
        }

       ……
       ……
0 0 vote
Article Rating
Subscribe
提醒
0 评论
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Scroll to Top