我试图将任何访问我的网站的pipe理部分的人redirect到它的HTTPS版本。 当前的重写规则如下:
server { listen 80; server_name domain.com; location / { index index.php index.html; root /home/domain.com/public; } #Redirect Admin requests to secure server location /www/admin/ { rewrite ^/(.*) https://domain.com$1 permanent; } }
这个规则的问题是它只是转发http://domain.com/www/admin HTTPS – 去http://domain.com/www/admin/index.php ,例如,不redirect。 任何想法如何纠正这一点,以便任何以下/www/admin也被redirect?
阅读由AlexD链接的wiki条目中的四条规则。 正则expression式位置(如您的PHP位置)优先于纯静态位置。 为了防止这种情况,你想在你的静态位置使用^~标志:
location ^~ /www/admin/ { rewrite ^ https://domain.com$request_uri? permanent; }
编辑:另外,你不应该设置你的根位于/ 。 将其设置在服务器中,让所有位置都inheritance该设置。 见陷阱和常见错误 1.2
查看nginx文档以获取位置指令的描述。 你应该使用location而不是location =