簡體   English   中英

Apache2 (2.4.7 Ubuntu 14.04 LTS) 中的 ProxyPass 工作主機名太長,如何解決這個問題?

[英]ProxyPass worker hostname too long in apache2 (2.4.7 Ubuntu 14.04 LTS), how to get around this?

我必須從內部 AWS ELB 設置 apache2 作為反向代理。 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 設置相同的/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]

如果您的網址太長,請改用 Alise,它對我有用。 在您的 mod_proxy.conf 文件中:

艾莉絲 http://dummy:8009 http://yourlongoriginalurl:8009

Proxypass / http://dummy:8009

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM