【发布时间】:2016-09-29 11:26:00
【问题描述】:
我尝试将来自非本地主机连接的所有请求从 http 重定向到 https。
我使用this combination https-> nginx -> varnish -> apache2 并希望将直接连接重定向到没有 ssl 的 apache
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
这不行
更新 1
我把这个:
RewriteCond %{REMOTE_ADDR} !=localhost
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
这是工作 - 浏览器中的 url 被重定向到 https:// 但我有无限循环,所以 apache 重定向到 https:// nginx 作为 http 的 apache 并重定向。如何解决?
更新 2
如果我换行
RewriteCond %{REMOTE_ADDR} !=localhost
到
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
重定向停止工作
更新 3 这不起作用,因为我有
http -> 清漆 -> apache 要么 https -> nginx -> 清漆 -> apache
所以对于 apache 来说一直有 127.0.0.1 所以我需要知道这是直接来自 http 或 varnish 的清漆请求
也许在 nginx 中添加一些 var(头文件?),如果请求在 apache htacces 中没有这个头文件,则重定向到 https。最好的方法是什么?
更新 4 我设置了我的 nginx -
add_header Mea-request nginx;
和
在阿帕奇
RewriteCond %{HTTP:Mea-request} != ^nginx$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
但这仍然不起作用
我认为这条线不正确
RewriteCond %{HTTP:Mea-request} != ^nginx$
【问题讨论】:
标签: apache .htaccess ssl nginx