Apache-2.4

代理 api 子目錄時出現 Apache 500 錯誤

  • February 11, 2022

我正在嘗試將對特定端點的 PUT 請求重定向到另一台主機。

所述端點位於/internal並僅接受 PUT 請求。下面的其他端點/internal將繼續由我的主主機/伺服器提供服務。

我已經嘗試使用重寫規則和使用代理([P])標誌和使用ProxyPass指令來設置它 - 所有這些都會導致 500 Internal Server Error 並且請求永遠不會到達新主機

我的客戶端應用程序使用無法處理重定向的簡單 REST 客戶端,因此我必須使用某種代理。

Apache 日誌顯示以下內容

[Thu Feb 10 08:56:20.394444 2022] [rewrite:trace1] [pid 8579] mod_rewrite.c(480): [client XXX.XXX.XXX.XXX:XXXXX] XXX.XXX.XXX.XXX - - [subdomain1.mydomain.com/sid#55d4ed07ecb0][rid#55d4ed2c5f20/initial] go-ahead with proxy request proxy: https://subdomain2.mydomain.com/internal/my-endpoint [OK]

這是特定虛擬主機的目前配置

<VirtualHost *:80>
ServerName subdomain1.mydomain.com
 ProxyPass /soap ajp://localhost:7007/soap retry=3
 ProxyPreserveHost On
 Redirect /  https://subdomain1.mydomain.com/
 ErrorLog /var/log/httpd/subdomain1_error
</VirtualHost>

<VirtualHost *:443>
 ServerName subdomain1.mydomain.com
 Options FollowSymlinks
 ProxyRequests On
 ProxyPreserveHost On
 #RewriteEngine On

 #RewriteCond %{REQUEST_URI} '^/internal/my-endpoint'
 #RewriteCond %{REQUEST_METHOD} ^(PUT)
 #RewriteRule "^/(.*)" "https://subdomain2.mydomain.com/internal/my-endpoint" [P]

 ProxyPass /internal/my-endpoint https://subdomain2.mydomain.com/internal/my-endpoint
 ProxyPassReverse /internal/my-endpoint https://subdomain2.mydomain.com/internal/my-endpoint
 ProxyPreserveHost On

 LogLevel alert rewrite:trace3
 CustomLog /var/log/httpd/subdomain1_access_log common
 ProxyPass / ajp://localhost:7007/ retry=3
 ProxyPassReverse / ajp://localhost:7007/ retry=3
 ProxyPreserveHost Off
 ErrorLog /var/log/httpd/subdomain1
 SSLEngine on
</VirtualHost>

好的-在 apache 日誌中啟用調試後,事實證明問題與 SSL 證書有關,因為代理與僅接受 HTTPS 連接的伺服器有關

必須將 apache 配置更新為以下配置才能使其正常工作

<VirtualHost *:80>
ServerName subdomain1.mydomain.com
 ProxyPass /soap ajp://localhost:7007/soap retry=3
 ProxyPreserveHost On
 Redirect /  https://subdomain1.mydomain.com/
 ErrorLog /var/log/httpd/subdomain1_error
</VirtualHost>

<VirtualHost *:443>
 ServerName subdomain1.mydomain.com
 Options FollowSymlinks
 ProxyRequests Off
 ProxyErrorOverride off
 ProxyPreserveHost On
######
 SSLEngine on
 SSLProxyEngine on
######

 ProxyPass /internal/my-endpoint https://subdomain2.mydomain.com/internal/my-endpoint
 ProxyPassReverse /internal/my-endpoint https://subdomain2.mydomain.com/internal/my-endpoint

 LogLevel alert rewrite:trace3
 CustomLog /var/log/httpd/subdomain1_access_log common
 ProxyPass / ajp://localhost:7007/ retry=3
 ProxyPassReverse / ajp://localhost:7007/ retry=3
 ProxyPreserveHost Off
 ErrorLog /var/log/httpd/subdomain1
 SSLEngine on
</VirtualHost>

引用自:https://serverfault.com/questions/1093285