URL重写重写规则在港口AWS不当添加

人气:1,050 发布:2022-09-12 标签: apache mod-rewrite amazon-web-services

问题描述

我在哪里,我们都在同一个EC2实例上运行两个系统,并使用AWS弹性负载平衡器发送请求一个系统端口81的问题。

I have an issue where we are running two systems on the same EC2 instances and using AWS Elastic Load Balancer to send request for one systems to port 81.

因此​​,例如,我们有www.example.com和bookings.example.com其中AWS弹性负载平衡器发送请求预订。虽然我们在端口80和要求WWW EC2盒。得到81端口,虽然发送。

So for example we have www.example.com and bookings.example.com where the AWS Elastic Load Balancer sends requests for bookings. though to our EC2 boxes on port 80 and request for www. get sent though on port 81.

客户连接到www.example.com上的端口80,但随后会从负载均衡器到服务器上的端口81。

The customer connects to www.example.com on port 80 but then gets from the load balancer to the server on port 81.

当我们如添加此规则的的.htaccess的WWW网站,我们有81端口的问题出现。

When we add this rule for example to the .htaccess for the www site we have an issues with port 81 appearing.

RewriteRule ^index.html / [R=301,L,QSA] !-s
#Results in customer being sent to http://www.example.com:81/

我怎样才能确保端口81是不推回给客户?

How can I make sure the port 81 is not pushed back to the customer?

我想出了这个另类:

RewriteRule ^index.html http://%{HTTP_HOST}/ [R=301,L,QSA] !-s

但在这个例子中的http很难codeD,我需要作出这样的变量,以便在需要的时候也可以是HTTPS。我也有更多的则只是重定向到/我对30的规则,并认为这index.html的规则应该有一个衬垫固定返还给客户通过这个端口81。

But in this example http is hard coded and I would need to make that variable so it can be https when needed. I also have more then just this index.html rule that redirect back to / I have about 30 rules and feel there should be a one liner to fix this passing port 81 back to the customer.

推荐答案

您可选择将运行,可以扩展支持SSL,但它可能没有必要。创建自引用的URL时阿帕奇遵循特定的顺序。 UseCanonicalName 和的 UseCanonicalPhysicalPort 控制模块(mod_rewrite的,启用mod_alias等)他们是如何考虑创建。

Your alternative will work and could be extended for ssl support, but it's probably not necessary. Apache follows a specific order when creating self referencing URL's. UseCanonicalName, and UseCanonicalPhysicalPort control how they are created regardless of the module (mod_rewrite, mod_alias, etc).

不知道更多你的配置,我建议首先是在合适的虚拟主机,这些指令。

Without knowing more of your configuration, I would suggest starting with these directives in the appropriate VirtualHost.

UseCanonicalName On
ServerName www.example.com:80

修改:如果你不希望这样做不管出于什么原因,这里是你如何解决您重写以支持SSL

EDIT: If you don't want to do this for whatever reason, here's how you fix your rewrite to support ssl.

RewriteCond %{HTTPS} =on
RewriteRule - - [env=req_scheme=http,S=1]
RewriteRule - - [env=req_scheme=https]

RewriteRule ^index.html %{ENV:req_scheme}://%{HTTP_HOST}/ [R=301,L,QSA]

164