【发布时间】:2021-04-19 22:19:57
【问题描述】:
所以基本上我写了一个代码来将我所有的 http(:80) 请求重定向到 https(:443), https-redirect.conf:
<VirtualHost *:80>
ServerName example.com
#ServerAlias *example.com
Redirect permanent / https://www.example.com/
# LogLevel debug
# ErrorLog /etc/httpd/logs/error_http.log
# CustomLog /etc/httpd/logs/error_http.log combined
</VirtualHost>
起初它确实有效,即当有人键入 example.com 时它重定向到 https://www.example.com 但是当有人键入 www.example.com 它重定向到 http://www.example.com 而不是 https
所以为了克服这个问题,我在这里使用了ServerAlias *example.com(甚至ServerName www.example.com),它确实有效,但我最终得到了 ERR_TOO_MANY_REDIRECTS 谁能帮忙,我什至在任何地方都找不到合适的解释.我什至尝试寻找潜在的循环但不能。
反向代理.conf:
<VirtualHost *:80>
ServerName example.com
ServerAlias *example.com
ProxyPreserveHost On
ProxyRequests Off
AllowEncodedSlashes NoDecode
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
RequestHeader set X-Forwarded-Proto http
RequestHeader set X-Forwarded-Port 80
ProxyPass "/" "http://example_ip:8080/"
ProxyPassReverse "/" "http://example_ip:8080/"
LogLevel debug
ErrorLog /etc/httpd/logs/error.log
CustomLog /etc/httpd/logs/error.log combined
</VirtualHost>
上面的代码是将 :8080 请求重定向到 :80 的代码
【问题讨论】:
标签: apache redirect reverse-proxy httpd.conf http-redirect