我必须将apache2设置为内部AWS ELB的反向代理。ELB的URL长度为85个字符。使用虚拟主机设置它失败,因为它给出一个错误
ProxyPass worker hostname (internal-elb-greater-than-64-character-url-that-fails-in-apache-aws.amazon.com) too long.
如果ELB URL小于或等于64个字符,则此操作非常有效。
配置看起来像这样在文件/etc/apache/sites-enabled/000-sites.conf
(实际ELB和网站的名称替换)
<VirtualHost *:80>
ProxyPreserveHost On
ServerName www.mydomain.com
ServerAdmin me@mydomain.com
DocumentRoot /var/www/html
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker.*
RewriteRule . https://www.mydomain.com%{REQUEST_URI} [R=301,L]
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPass /test/ http://localhost:8080/
ProxyPassReverse /test/ http://localhost:8080/
ProxyPass / http://internal-elb-greater-than-64-character-url-that-fails-in-apache-aws.amazon.com/
ProxyPassReverse / http://internal-elb-greater-than-64-character-url-that-fails-in-apache-aws.amazon.com/
</VirtualHost>
我已经能够设置相同的nginx与以下配置文件/etc/nginx/nginx.conf
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
#access_log /var/log/nginx/host.access.log main;
location /test/ {
if ( $http_x_forwarded_proto != 'https' ){
rewrite ^ https://www.mydomain.com$request_uri? permanent;
}
proxy_pass http://localhost:8080/;
}
location / {
if ( $http_x_forwarded_proto != 'https' ){
rewrite ^ https://www.mydomain.com$request_uri? permanent;
}
proxy_pass http://internal-elb-greater-than-64-character-url-that-fails-in-apache-aws.amazon.com/;
}
location /elb-status {
return 200;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Nginx工作如预期-与PING URL健康检查修改。
我想知道apache2 (2.4.7 Ubuntu 14.0 LTS)中的等效配置是什么。我在Fedora的apache2.4.9上尝试了一下,结果还是一样的。
如何让apache2工作,因为我们没有考虑nginx之前的内部负载平衡-这不是我的决定
您需要使用mod_rewrite:
https://issues.apache.org/bugzilla/show_bug.cgi?id=53218关于重写:http://httpd.apache.org/docs/2.4/rewrite/
所以我的猜测(未测试):
RewriteRule ^/(.*)$ http://internal-elb-greater-than-64-character-url-that-fails-in-apache-aws.amazon.com/$1 [P]
如果你的url太长,请使用Alise代替,它为我工作。在mod_proxy.conf文件中:
Alise http://dummy:8009 http://yourlongoriginalurl:8009
Proxypass/http://dummy:8009