在过去的几天里,我一直试图迫使我的应用程序将一个非https调用转发到我的域中。
我有一个Web弹性豆柄,配置了64位Amazon 2016.03,v2.2.0,运行Tomcat8Java8。我在我的应用程序中创建了一个文件夹,名为.ebextensions,文件名为ssl_rewrite.config。该文件包含以下内容:
files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R]它曾经包含这个,taken from this example,但是我收到了if语句的错误:
files:
"/etc/httpd/conf.d/ssl_rewrite.conf":
mode: "000644"
owner: root
group: root
content: |
RewriteEngine On
<If "-n '%{HTTP:X-Forwarded-Proto}' && %{HTTP:X-Forwarded-Proto} != 'https'">
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</If>无论如何,当我试图部署我的应用程序时,它失败了,我得到了以下错误:
Application update failed at 2016-10-17T01:33:00Z with exit status 1 and error: Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/03_configure_proxy.sh failed.
Executing: /opt/elasticbeanstalk/bin/log-conf -n httpd -l'/var/log/httpd/*'
Executing: /usr/sbin/apachectl -t -f /var/elasticbeanstalk/staging/httpd/conf/httpd.conf
Syntax error on line 1 of /etc/httpd/conf.d/ssl_rewrite.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Failed to execute '/usr/sbin/apachectl -t -f /var/elasticbeanstalk/staging/httpd/conf/httpd.conf'
Failed to execute '/usr/sbin/apachectl -t -f /var/elasticbeanstalk/staging/httpd/conf/httpd.conf'.我已经进入了httpd.conf文件并添加了一行:
LoadModule rewrite_module模块/mod_rewrite.so
关于我做错了什么有什么建议或想法吗?谢谢!
发布于 2018-10-04 07:41:11
对于那些挣扎了一段时间的人,我找到了一个GitHub (来自AWS团队),其中包含了所有AWS的信息,下面的示例适用于Apache2.2的HTTP>HTTPS重定向。(有关Apache2.4和Nginx的信息,请参见下面的链接)。
Apache2.2
有关Apache2.4和Nginx的更多示例,请访问此GitHub存储库:
此外,还有更多有用的配置和示例可用。
问候
发布于 2016-12-23 16:41:25
我终于能让我的工作:
LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI} [L,R]此外,我发现只需将一个ssl_rewrite.conf放在我的.eb扩展名/httpd/conf.d.d文件夹中就更容易了,并让AWS脚本处理剩下的部分。
如果使用虚拟主机,也请阅读rewrite.html#vhosts。虚拟主机不会从主服务器上下文继承Mod_rewrite配置,因此在每个虚拟主机配置中也需要以下内容。
RewriteEngine On
RewriteOptions Inherit在64位Amazon 2016.09 v2.4.0上进行测试,运行Tomcat7Java7。
https://stackoverflow.com/questions/40096736
复制相似问题