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

n7taea2i  于 2022-11-25  发布在  Apache
关注(0)|答案(3)|浏览(171)

使用环境:操作系统中心
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
<VirtualHost *:80>
ServerName example.com localhost

ServerAlias example
DocumentRoot ......

DirectoryIndex index.shtml index.html index.jsp
AddType text/html .shtml
AddHandler server-parsed .shtml
AddType application/x-httpd-php .php .php4

CustomLog /var/log/httpd/access_log combined env=!dontlog
ErrorLog /var/log/httpd/error_log

RewriteEngine on
RewriteCond "%{HTTPS}" !="on"
RewriteRule ^/(.*)$ https://example.com/$1 [R=301,L]
....

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link {color: #000099; text-decoration: none; background-color: #ffffff;}
a:hover {text-decoration: underline;}
table {border-collapse: collapse;}
.center {text-align: center;}
.center table { margin-left: auto; margin-right: auto; text-align: left;}
.center th { text-align: center !important; }
td, th { border: 1px solid #000000; font-size: 75%; vertical-align: baseline;}
h1 {font-size: 150%;}
h2 {font-size: 125%;}
.p {text-align: left;}
.e {background-color: #ccccff; font-weight: bold; color: #000000;}
.h {background-color: #9999cc; font-weight: bold; color: #000000;}
.v {background-color: #cccccc; color: #000000;}
.vr {background-color: #cccccc; text-align: right; color: #000000;}
img {float: right; border: 0px;}
hr {width: 600px; background-color: #cccccc; border: 0px; height: 1px; color: #000000;}
</style>
<title>phpinfo()</title><meta name="ROBOTS" content="NOINDEX,NOFOLLOW,NOARCHIVE" /></head>
<body><div class="center">
<h2>PHP Variables</h2>
<table border="0" cellpadding="3" width="600">
<tr class="h"><th>Variable</th><th>Value</th></tr>
<tr><td class="e">_SERVER["dontlog"]</td><td class="v">1</td></tr>
<tr><td class="e">_SERVER["SCRIPT_URL"]</td><td class="v">test.php</td></tr>
<tr><td class="e">_SERVER["SCRIPT_URI"]</td><td class="v">test.php</td></tr>
<tr><td class="e">_SERVER["HTTP_HOST"]</td><td class="v">example.com</td></tr>
<tr><td class="e">_SERVER["HTTP_UPGRADE_INSECURE_REQUESTS"]</td><td class="v">1</td></tr>
<tr><td class="e">_SERVER["HTTP_USER_AGENT"]</td><td class="v">Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36</td></tr>
<tr><td class="e">_SERVER["HTTP_ACCEPT"]</td><td class="v">text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8</td></tr>
<tr><td class="e">_SERVER["HTTP_ACCEPT_ENCODING"]</td><td class="v">gzip, deflate, sdch, br</td></tr>
<tr><td class="e">_SERVER["HTTP_ACCEPT_LANGUAGE"]</td><td class="v">en-US,en;q=0.8</td></tr>
<tr><td class="e">_SERVER["HTTP_X_FORWARDED_FOR"]</td><td class="v">::1</td></tr>
<tr><td class="e">_SERVER["HTTP_X_FORWARDED_HOST"]</td><td class="v">example.com</td></tr>
<tr><td class="e">_SERVER["HTTP_X_FORWARDED_SERVER"]</td><td class="v">example.com</td></tr>
<tr><td class="e">_SERVER["HTTP_CONNECTION"]</td><td class="v">Keep-Alive</td></tr>
<tr><td class="e">_SERVER["PATH"]</td><td class="v">/sbin:/usr/sbin:/bin:/usr/bin</td></tr>
<tr><td class="e">_SERVER["SERVER_SIGNATURE"]</td><td class="v">&lt;address&gt;Apache/2.2.15 (CentOS) Server at example.com Port 80&lt;/address&gt;
</td></tr>
<tr><td class="e">_SERVER["SERVER_SOFTWARE"]</td><td class="v">Apache/2.2.15 (CentOS)</td></tr>
<tr><td class="e">_SERVER["SERVER_NAME"]</td><td class="v">example.com</td></tr>
<tr><td class="e">_SERVER["SERVER_ADDR"]</td><td class="v">::1</td></tr>
<tr><td class="e">_SERVER["SERVER_PORT"]</td><td class="v">80</td></tr>
<tr><td class="e">_SERVER["REMOTE_ADDR"]</td><td class="v">::1</td></tr>
<tr><td class="e">_SERVER["DOCUMENT_ROOT"]</td><td class="v">.....</td></tr>
<tr><td class="e">_SERVER["SERVER_ADMIN"]</td><td class="v">root@localhost</td></tr>
<tr><td class="e">_SERVER["SCRIPT_FILENAME"]</td><td class="v">test.php</td></tr>
<tr><td class="e">_SERVER["REMOTE_PORT"]</td><td class="v">57954</td></tr>
<tr><td class="e">_SERVER["GATEWAY_INTERFACE"]</td><td class="v">CGI/1.1</td></tr>
<tr><td class="e">_SERVER["SERVER_PROTOCOL"]</td><td class="v">HTTP/1.1</td></tr>
<tr><td class="e">_SERVER["REQUEST_METHOD"]</td><td class="v">GET</td></tr>
<tr><td class="e">_SERVER["QUERY_STRING"]</td><td class="v"><i>no value</i></td></tr>
<tr><td class="e">_SERVER["REQUEST_URI"]</td><td class="v">test.php</td></tr>
<tr><td class="e">_SERVER["SCRIPT_NAME"]</td><td class="v">test.php</td></tr>
<tr><td class="e">_SERVER["PHP_SELF"]</td><td class="v">test.php</td></tr>
<tr><td class="e">_SERVER["REQUEST_TIME"]</td><td class="v">1483559123</td></tr>
</table><br />
</div></body></html>

请告知

enyaitl3

enyaitl31#

更改此项:

RewriteCond "%{HTTPS}" !="on"

对此:

RewriteCond %{HTTPS} off

不要用SetEnv自己设置它,mod_rewrite会处理它。
该重定向位于端口80的<VirtualHost>中,因此如果在https上传入,我不知道该如何处理(因此不需要进行检查),因为在这种情况下会处理另一个虚拟主机。您确定您没有忽略其中某些规则的.htaccess吗?否则,请公布您的虚拟主机块。2同时清除您的缓存或尝试不同的浏览器。

4ngedf3f

4ngedf3f2#

修复..这都是因为错误的配置..

ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/

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

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

uqxowvwt3#

对我来说,这与CloudFlare的“灵活的”SSL/TSL加密模式有关。将其设置为“完全”解决了我的重定向循环。

相关问题