Apache2 和 proxy_balancer BalanceMember

Apache2 和 proxy_balancer BalanceMember

我有这个 Apache2 站点配置,允许我“运行 Apache 作为代理”服务localhost:8080

<VirtualHost *:80>
    ServerName foo.mydomain.com
    RedirectPermanent / https://foo.mydomain.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName foo.mydomain.com

    RewriteEngine On

    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
    RewriteRule ^/(.*)$ balancer://upstream%{REQUEST_URI} [P,QSA,L]

    <Proxy balancer://upstream>
        # following directive generates the error
        BalancerMember http://127.0.0.1:8080
    </Proxy>

    ProxyRequests Off
    ProxyVia On
    ProxyPreserveHost On
    RequestHeader set X_FORWARDED_PROTO https

    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>

    SSLEngine               on
    SSLCertificateFile      /etc/apache2/certs/foo.mydomain.com/host.pem
    SSLCertificateKeyFile   /etc/apache2/certs/foo.mydomain.com/host.key

    ErrorLog ${APACHE_LOG_DIR}/error_foo_mydomain.log

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access_foo_mydomain.log combined
</VirtualHost>

当我重新启动 Apache2 时,service apache2 restart返回错误。
我发现问题与以下指令有关:

BalancerMember http://127.0.0.1:8080

如果我注释掉该行,错误就会消失,服务器也会启动。然而,代理无法正常工作。语法应该是正确的,所以我不知道如何解决这个问题。

当然,proxyproxy_balancer模块都已启用。

答案1

我找到了一个允许我代理localhost:8080服务的解决方案。

<VirtualHost *:80>
    ServerName foo.mydomain.com
    RedirectPermanent / https://foo.mydomain.com/
</VirtualHost>

<VirtualHost *:443>
    ServerName foo.mydomain.com

    ProxyPass / http://127.0.0.1:8080/
    ProxyPassReverse / http://127.0.0.1:8080/

    SSLEngine               on
    SSLCertificateFile      /etc/apache2/certs/foo.mydomain.com/host.pem
    SSLCertificateKeyFile   /etc/apache2/certs/foo.mydomain.com/host.key

    ErrorLog ${APACHE_LOG_DIR}/error_foo_mydomain.log

    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access_foo_mydomain.log combined
</VirtualHost>

相关内容