nginx服务器http重定向到https的正确写法

发表时间:2014-11-26 15:58 | 分类:Linux | 浏览:8,088 次

把http重定向到https使用了nginx的重定向命令。那么应该如何写重定向?之前老版本的nginx可能使用了以下类似的格式。

rewrite ^/(.*)$ http://domain.com/$1 permanent;
或者
rewrite ^ http://domain.com$request_uri? permanent;

现在nginx新版本已经换了种写法,上面这些已经不再推荐。现在网上可能还有很多文章写的是第一种。比如博主的这篇文章《LNMP环境实现301重定向的方法》。

下面是nginx http页面重定向到https页面最新支持的写法:

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

server {
       listen         443 ssl;
       server_name    my.domain.com;

       [....]
}

 

参考网址:

http://serverfault.com/questions/67316/in-nginx-how-can-i-rewrite-all-http-requests-to-https-while-maintaining-sub-dom

http://wiki.nginx.org/Pitfalls#Taxing_Rewrites

本文标签:

本文链接:https://www.sijitao.net/1829.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

已经有2个回复
Comment (2)
Trackbacks (0)
  1. an9  ( 2015.04.13 21:41 ) : #-9

    正在学习。

  2. 松果  ( 2015.04.27 20:38 ) : #-8

    收藏了 :twisted:

  1. 还没有Trackbacks
一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.