如何将elasticbeanstalk.com上支持Apache的代理重定向到自定义域?
我正在使用Tomcat在Elastic Beanstalk中运行一个应用程序。我为我的环境设置了自己的域名,并将其添加为如何将elasticbeanstalk.com上支持Apache的代理重定向到自定义域?,apache,mod-rewrite,redirect,amazon-web-services,amazon-elastic-beanstalk,Apache,Mod Rewrite,Redirect,Amazon Web Services,Amazon Elastic Beanstalk,我正在使用Tomcat在Elastic Beanstalk中运行一个应用程序。我为我的环境设置了自己的域名,并将其添加为xyz.elasticbeanstalk.com地址的CNAME别名,一切正常。我想做的是将访问xyz.elasticbeanstalk.com网站的流量重定向到我自己的域名 我想我可以在我的WAR文件中使用.ebextensions这样做: myapp.config: container_commands: 01_setup_rewrite: comm
xyz.elasticbeanstalk.com
地址的CNAME别名,一切正常。我想做的是将访问xyz.elasticbeanstalk.com
网站的流量重定向到我自己的域名
我想我可以在我的WAR文件中使用.ebextensions这样做:
myapp.config:
container_commands:
01_setup_rewrite:
command: "cp .ebextensions/redirect_canonical.conf /etc/httpd/conf.d/redirect_canonical.conf"
02_apache_restart:
command: /etc/init.d/httpd restart
重定向_canonical.conf:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.mydomain.com/$1 [L,R,NE]
我以前在.htaccess
文件中使用过类似的mod_重写规则,它们工作得很好,但由于这是一个mod_代理,我不确定这是否正确(或者我是否可以将rewrite命令放在conf.d文件夹中)
如何配置它并按照我的意愿重定向?根据Mason G.Zhwiti对相关问题的回答,我认为您需要以类似于Apache的方式来实现这一点,例如,类似这样的方式(由于缺乏实际测试时间,因此省略了Bash脚本):
祝你好运 你最后明白了吗?
files:
"/tmp/45_apache_redirect_canonical.sh":
owner: root
group: root
mode: "000644"
content: |
#! /bin/bash
# TODO: create script that injects content of your 'redirect_canonical.conf'
# into (presumably) '/etc/httpd/conf.d/00_elastic_beanstalk_proxy.conf'
container_commands:
00_appdeploy_rewrite_hook:
command: cp -v /tmp/45_apache_redirect_canonical.sh /opt/elasticbeanstalk/hooks/appdeploy/enact
01_configdeploy_rewrite_hook:
command: cp -v /tmp/45_apache_redirect_canonical.sh /opt/elasticbeanstalk/hooks/configdeploy/enact
02_rewrite_hook_perms:
command: chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/enact/45_apache_redirect_canonical.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_apache_redirect_canonical.sh
03_rewrite_hook_ownership:
command: chown root:users /opt/elasticbeanstalk/hooks/appdeploy/enact/45_apache_redirect_canonical.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_apache_redirect_canonical.sh