ApacheでProxyPassを介してサーバー情報にアクセスする方法は?

ApacheでProxyPassを介してサーバー情報にアクセスする方法は?

背後には3つのWebサーバー(a、b、c)があり、すべてApacheとRHEL 8を実行するロードバランサーがあります。私がやりたいことは比較的簡単です。 http://loadbalancer/a/server-status、http://loadbalancer/b/server-statusを介してロードバランサーの背後にあるボックスのApacheサーバーの状態を取得したいと思います。など。

http://ipofbox:8000/server-status を使用してボックスに直接アクセスすると、サーバーの状態が正常に動作します。

ロードバランサーの httpd.conf には次の行があります。

<VirtualHost *:80>

ProxyRequests off

#Start Proxy balancer block and define cluster
<Proxy balancer://thecluster>

    BalancerMember http://172.31.19.205:8080
    BalancerMember http://172.31.28.85:8080 loadfactor=3
    BalancerMember http://172.31.28.49:8080
    #weighted traffic byte count balancing
    ProxySet lbmethod=bytraffic nofailover=off

</Proxy>

ProxyPass /worksa http://172.31.19.205:8080
ProxyPass /worksb http://172.31.28.85:8080
ProxyPass /worksc http://172.31.28.49:8080

ProxyPass /a http://172.31.19.205:8000
ProxyPass /b http://172.31.28.85:8000
ProxyPass /c http://172.31.28.49:8000

#pass through any other proxy requests
ProxyPass / balancer://thecluster/

#route traffic back through the cluster and act as a load balancer, ensure headers generated from any workers are modified to point to the load balancer, masking the backend web servers
#ProxyPassReverse / balancer://thecluster/

#balancer-manager GUI via port 80
<Location /balancer-manager>
    SetHandler balancer-manager
</Location>

#don't pass requests to the BM through to the cluster
ProxyPass /balancer-manager !

<Location "/~Alice">
    AuthType Digest
    AuthName "private"
    AuthDigestDomain "/~Alice"
    AuthDigestProvider file
    AuthUserFile "/etc/httpd-auth/digest_passwords_file2"
    Require valid-user
</Location>

<Location "/~Bob">
    AuthType Digest
    AuthName "private"
    AuthDigestDomain "/~Bob"
    AuthDigestProvider file
    AuthUserFile "/etc/httpd-auth/digest_passwords_file2"
    Require valid-user
</Location>

</VirtualHost>

<VirtualHost *:8000>
ProxyRequests off

#server-info GUI via port 8000
<Location /server-info>
    SetHandler server-info
</Location>

#server-status GUI via port 8000
<Location /server-status>
    SetHandler server-status
</Location>

<Location "/server-info">
    AuthType Digest
    AuthName "realm"
    AuthDigestDomain "/server-info"
    AuthDigestProvider file
    AuthUserFile /etc/httpd-auth/digest_passwords_file
    Require valid-user
</Location>

<Location "/server-status">
    AuthType Digest
    AuthName "realm"
    AuthDigestDomain "/server-status"
    AuthDigestProvider file
    AuthUserFile /etc/httpd-auth/digest_passwords_file
    Require valid-user
</Location>

</VirtualHost>

編集する:今は過ぎたようですが今回は400不良要請を受けました。要求を処理するバックエンドサーバーのエラーログには、次のものが表示されます。

[auth_digest:error] [pid 9105:tid 139830629422848] [client ***.***.***.***:50720] AH01786: uri mismatch - </a/server-info/> does not match request-uri </server-info/>

ダイジェスト認証が有効になっていると、ロードバランサーからアクセスするとアクセスが失敗するようです。 Worksaには次のものがあります。

Worksaには次のものがあります。

<VirtualHost *:8000>

#balancer-manager GUI via port 8000
<Location /balancer-manager>
    SetHandler balancer-manager
</Location>

#Req 4.b
<Location "/server-info">
    SetHandler server-info
    AuthType Digest
    AuthName "realm"
    AuthDigestDomain "/server-info"
    AuthDigestProvider file
    AuthUserFile /etc/httpd-auth/digest_passwords_file
    Require valid-user
</Location>

# Req 4.a, Req 4.b
<Location "/server-status">
    SetHandler server-status
    AuthType Digest
    AuthName "realm"
    AuthDigestDomain "/server-status"
    AuthDigestProvider file
    AuthUserFile /etc/httpd-auth/digest_passwords_file
    Require valid-user
</Location>

</VirtualHost>

次に、http://loadbalancer/worksa/index.htmlにアクセスしようとすると、403 Forbiddenが表示され、worksaのアクセスログは次のようになります。

(13)Permission denied: file permissions deny server access: /var/www/html/index.html.

index.htmlでchmod 0644を使用しましたが、役に立たないようです。

要約すると、http://loadbalancer/a/server-infoは資格情報を要求し、400 Bad Requestを返しますが、http://loadbalancer/a/index.htmlは403 Forbiddenを返します。

とても感謝しています。

ベストアンサー1

ProxyPassバランサーの前に特定の指示を移動すると、バランサーはProxyPass他のすべてと一致します/。末尾のスラッシュを削除します。

これは最初の仮想ホストです。

<VirtualHost *:80>
    ProxyRequests off

    #Start Proxy balancer block and define cluster
    <Proxy balancer://thecluster>
        BalancerMember http://172.31.27.155:8080
        BalancerMember http://172.31.21.185:8080 loadfactor=3
        BalancerMember http://172.31.28.201:8080

        #weighted traffic byte count balancing
        ProxySet lbmethod=bytraffic nofailover=off
    </Proxy>

    ProxyPass /worksa http://172.31.27.155:8080
    ProxyPass /worksb http://172.31.21.185:8080
    ProxyPass /worksc http://172.31.28.201:8080

    # pass through balancer member
    ProxyPass /a http://172.31.27.155:8000
    ProxyPass /b http://172.31.21.185:8000
    ProxyPass /c http://172.31.28.201:8000

    # pass through any other proxy requests
    ProxyPass / balancer://thecluster/

    #route traffic back through the cluster and act as a load balancer, ensure headers generated from$
    #ProxyPassReverse / balancer://thecluster/
</VirtualHost>

「403 Forbidden」を防ぐために、バックエンドでアクセス制御を調整する必要があるかもしれません。

<Location /server-status>
    SetHandler server-status
    # limit to ip addresses, hosts or whatever you need
    Require ip 172.31
</Location>

おすすめ記事