http到https apache重定向。。无限循环

http到https apache重定向。。无限循环,apache,redirect,Apache,Redirect,环境:CentOS Apache版本:Apache/2.2.15 我一直试图强迫我的网站是https,但遇到无限重定向 <VirtualHost *:443> ServerName example.com ServerAlias example SetEnv HTTPS on ProxyPreserveHost On ProxyPass / http://localhost/ ProxyPassReverse / http://localhost/ SSLEngine on S

环境:CentOS
Apache版本:Apache/2.2.15

我一直试图强迫我的网站是https,但遇到无限重定向

<VirtualHost *:443>
ServerName example.com
ServerAlias example 

SetEnv HTTPS on
ProxyPreserveHost On
ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/

SSLEngine on
SSLCertificateFile /ssl/star_ecom_sanmar_com.crt
SSLCertificateKeyFile /ssl/star_ecom_sanmar_com.key
SSLCertificateChainFile /ssl/DigiCertCA.crt
SSLProxyEngine on

ServerName example.com
服务器别名示例
SetEnv HTTPS on
代理主机
ProxyPass/http://localhost/
ProxyPassReverse/http://localhost/
斯伦金安
SSLCertificateFile/ssl/star\u ecom\u sanmar\u com.crt
SSLCertificateKeyFile/ssl/star_ecom_sanmar_com.key
SSLCertificateChainFile/ssl/DigiCertCA.crt
SSLProxyEngine打开


ServerName example.com本地主机
服务器别名示例
文档根。。。。。。
DirectoryIndex.shtml index.html index.jsp
AddType text/html.shtml
AddHandler服务器已解析。shtml
AddType应用程序/x-httpd-php.php.php4
CustomLog/var/log/httpd/access\u log组合环境=!唐特洛
ErrorLog/var/log/httpd/error\u log
重新启动发动机
重写条件“%{HTTPS}”=“关于”
重写规则^/(.*)$https://example.com/$1[R=301,L]
....

上面的重写规则总是在重定向到https之后执行,这会导致无限循环,这让我觉得{https}的值永远不会更新。{SERVER_PORT}的情况也是如此,即使请求来自https,它也始终为80。 下面是php的输出


正文{背景色:#ffffff;颜色:#000000;}
正文,td,th,h1,h2{字体系列:无衬线;}
前{margin:0px;字体系列:monospace;}
答:链接{color:#000099;文本装饰:无;背景色:#ffffff;}
a:悬停{文本装饰:下划线;}
表{边框折叠:折叠;}
.center{text align:center;}
.center表格{左边距:自动;右边距:自动;文本对齐:左;}
.center th{文本对齐:居中!重要;}
td,th{边框:1px实心#000000;字体大小:75%;垂直对齐:基线;}
h1{字体大小:150%;}
h2{字体大小:125%;}
.p{文本对齐:左;}
.e{背景色:#ccccff;字体大小:粗体;颜色:#000000;}
.h{背景色:#9999cc;字体重量:粗体;颜色:#000000;}
.v{背景色:#CCCC;颜色:#000000;}
.vr{背景颜色:#cccccc;文本对齐:右;颜色:#000000;}
img{float:right;border:0px;}
hr{宽度:600px;背景色:#cccccc;边框:0px;高度:1px;颜色:#000000;}
phpinfo()
PHP变量
可变值
_服务器[“dontlog”]1
_SERVER[“SCRIPT_URL”]test.php
_服务器[“脚本URI”]test.php
_服务器[“HTTP_HOST”]example.com
_服务器[“HTTP\u升级\u不安全的\u请求”]1
_服务器[“HTTP_USER_AGENT”]Mozilla/5.0(X11;Linux x86_64)AppleWebKit/537.36(KHTML,类似Gecko)Chrome/52.0.2743.116 Safari/537.36
_服务器[“HTTP_ACCEPT”]text/html,application/xhtml+xml,application/xml;q=0.9,图像/webp,*/*;q=0.8
_服务器[“HTTP\u接受\u编码”]gzip,deflate,sdch,br
_服务器[“HTTP_接受_语言”]en US,en;q=0.8
_服务器[“HTTP\u X\u转发给”]::1
_服务器[“HTTP\u X\u转发的\u主机”]example.com
_服务器[“HTTP\u X\u转发的\u服务器”]example.com
_服务器[“HTTP_连接”]保持活动状态
_服务器[“路径”]/sbin:/usr/sbin:/bin:/usr/bin
_服务器[“服务器签名”]地址Apache/2.2.15(CentOS)服务器位于example.com端口80/地址
_服务器[“服务器软件”]Apache/2.2.15(CentOS)
_服务器[“服务器名称”]example.com
_服务器[“服务器地址]::1
_服务器[“服务器端口”]80
_服务器[“远程地址]::1
_服务器[“文档根”]。。。。。
_服务器[“服务器管理”]root@localhost
_服务器[“脚本文件名”]test.php
_服务器[“远程_端口”]57954
_服务器[“网关接口”]CGI/1.1
_服务器[“服务器协议”]HTTP/1.1
_服务器[“请求\方法”]获取
_服务器[“查询字符串”]无值
_服务器[“请求URI”]test.php
_服务器[“脚本名称”]test.php
_服务器[“PHP_SELF”]test.PHP
_服务器[“请求时间”]1483559123

更改此选项:

RewriteCond "%{HTTPS}" !="on"
为此:

RewriteCond %{HTTPS} off
不要自己用SetEnv设置,mod_rewrite会处理它


这个重定向在端口80的
中,因此我不知道如果通过https进入,该重定向将如何处理(因此根本不需要检查),因为在这种情况下会处理另一个虚拟主机。你确定你没有一个
.htaccess
中有一些你忽略的规则吗?否则,请发布完整的虚拟主机块。也可以清除缓存或尝试其他浏览器。

修复。。这都是因为配置错误

ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/
在内部调用端口80 VirtualHost(ServerName是localhost),从而调用重定向循环。 通过将上述内容替换为

ProxyPass / ajp://localhost:8409/
ProxyPassReverse / ajp://localhost:8409/

在以下条件下也尝试过,但仍然得到无限重定向循环。RewriteCond%{SERVER_PORT}=80 RewriteRule^/(.*)$[R=301,L]尝试了上述解决方案,但仍然相同。。该规则在循环中执行
ProxyPass / ajp://localhost:8409/
ProxyPassReverse / ajp://localhost:8409/