我必须将 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>
我已经能够在文件
/etc/nginx/nginx.conf
中使用以下配置设置与 nginx 相同的设置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]
关于apache - apache2(2.4.7 Ubuntu 14.04 LTS)中的 ProxyPass worker 主机名太长,如何解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24260171/