您如何配置Apache站点以在负载AWS平衡器之后将所有http流量重定向到https?
很多similar questions不涉及负载均衡器。
我正在使用此配置来使重定向在没有负载均衡器的情况下工作:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias mydomain.com
ServerAdmin sysadmin@mydomain.com
DocumentRoot /usr/local/html
AllowEncodedSlashes On
<Location /server-status>
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Location>
LogLevel warn
ErrorLog ${APACHE_LOG_DIR}/error.log
# Log real IP since we're behind a load balancer.
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
# Redirect all non-https traffic to https.
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
</VirtualHost>
这非常有效,并将所有流量重定向到https。
但是,当我将服务器放置在当前的AWS负载均衡器之后时,Apache会正确重定向,但会显示错误页面:
Forbidden
You don't have permission to access this resource.
在我的日志中,看到错误:
AH01630: client denied by server configuration: /usr/local/html
这没有任何意义,因为没有负载均衡器就可以访问。发生了什么事?