我正在使用 AWS Elastic Load Balancer,并已设置遵循规则将http
流量转换为https
。
/etc/httpd/conf.d/httpd_redirect.conf
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>
但是,当我通过域名访问我的网站时(www.thewhozoo.com),我可以看到协议是http
但不是https
。
知道为什么重写规则不起作用吗?
谢谢
更多信息
/etc/httpd/conf/httpd.conf
...
Include conf.d/*.conf
Include conf.d/elasticbeanstalk/*.conf
...
以上内容是在部署时创建的:
.ebextensions/myapp.config
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
files:
"/etc/httpd/conf.d/httpd_redirect.conf" :
mode: "000644"
owner: root
group: root
content: |
<VirtualHost *:80>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>
ELB 监听器
答案1
您有一个配置片段/etc/httpd/conf.d/ssl_rewrite.conf
通常,此类代码片段由Include
或者IncludeOptional
指示
Include conf.d/*.conf
或者
IncludeOptional conf.d/*.conf
从你的主要httpd.conf
。
问题是这些代码片段仅适用于您的主配置,而不适用于任何VirtualHost
部分......
在虚拟主机定义中包含这些设置,或者在那里加载该代码片段:
<VirtualHost *:80>
ServerName www.thewhozoo.com
Include /etc/httpd/conf.d/ssl_rewrite.conf
</VirtualHost>
或者更好的是,不要使用 mod_rewrite并设置:
<VirtualHost *:80>
ServerName www.thewhozoo.com
Redirect "/" "https://www.thewhozoo.com/"
</VirtualHost>