apache - apache2(2.4.7 Ubuntu 14.04 LTS)中的 ProxyPass worker 主机名太长,如何解决这个问题?

标签 apache ubuntu nginx amazon-elb

我必须将 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/

相关文章:

ubuntu - 压缩所有文件甚至隐藏

php - Nginx 配置权限和所有权

javascript - Apache Cordova : Build failed Error code 1 and Javascript Exception

php - UTF-8贯穿始终

java - 为什么在尝试使用 Apache POI 打开 Excel 文件时出现异常 "IOException: ZIP entry size is too large"?

php - 没有通过 nginx/FastCGI 传递给 php-fpm 的脚本名称

node.js - nginx 拒绝连接 ec2 实例上的 Node 应用程序

Apache 将子域传递到备用路径

azure - 从镜像构建后 ssh 到 azure-vm

ubuntu - 不同Linux发行版的ansible相同剧本