代理 api 子目录时出现 Apache 500 错误

代理 api 子目录时出现 Apache 500 错误

我正在尝试将特定端点的 PUT 请求重定向到另一个主机。

所述端点位于 下/internal,并且仅接受 PUT 请求。 下的其他端点/internal将继续由我的主要主机/服务器提供服务。

[P]我尝试使用重写规则和代理( )标志以及指令进行设置ProxyPass- 所有这些都导致 500 内部服务器错误,并且请求永远不会到达新主机

我的客户端应用程序使用无法处理重定向的简单 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>

答案1

好的 - 在 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>

相关内容