【问题标题】:ProxyPass worker hostname too long in apache2 (2.4.7 Ubuntu 14.04 LTS), how to get around this?apache2(2.4.7 Ubuntu 14.04 LTS)中的 ProxyPass worker 主机名太长,如何解决这个问题?
【发布时间】:2014-08-07 06:01:20
【问题描述】:

我必须将 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 - 这不是我的决定。

【问题讨论】:

    标签: apache ubuntu nginx amazon-elb


    【解决方案1】:

    如果您的网址太长,请改用 Alise,它对我有用。在您的 mod_proxy.conf 文件中:

    Alise http://dummy:8009 http://yourlongoriginalurl:8009

    Proxypass / http://dummy:8009

    【讨论】:

      【解决方案2】:

      你需要使用 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]
      

      【讨论】:

      • 这不会重定向吗?维尔乔·维塔宁
      • @RuanCarlos no.参见重写文档,flag [P] = proxy。
      • 我看到了,但是当我尝试重定向时,当我直接放入虚拟服务器时,只有代理权。不过谢谢
      猜你喜欢
      • 1970-01-01
      • 2016-08-06
      • 2015-10-15
      • 2014-06-21
      • 1970-01-01
      • 2015-07-20
      • 2016-02-12
      • 2014-07-10
      • 2016-11-21
      相关资源
      最近更新 更多