使用 apache mod_proxy 时的应用程序错误通路

发布于 2024-08-26 20:00:07 字数 630 浏览 5 评论 0原文

嘿嘿。我使用 mod_proxy 和 apache2 为本地计算机上运行的多个 servlet 应用程序提供虚拟主机功能。在大多数情况下,它工作得很好。请求进入 apache,然后被定向到绑定在本地主机端口上的应用程序。应用程序接收请求并响应,由 apache 传回客户端。

我遇到的问题是应用程序会在错误时发出 500 错误,而 mod_proxy 则会对其进行踩踏。通常这些错误是在 ajax 请求中引起的,并且错误在客户端 JavaScript 中处理。例如,对服务器端 createObject(name) 的调用可能会抛出 NameNotUniqueException ,该异常会以 500 的形式返回。然后,客户端 javascript 可能会显示相应的错误消息。

当应用程序抛出错误(导致对 mod_proxy 的 500 响应)时,apache 会停止该错误消息并返回

500 Internal Server Error

Internal Server Error

服务器遇到内部错误或 配置错误并且无法完成 您的要求。

.. 库存 apache 服务器端错误消息。

我希望 mod_proxy 将原始 500 传递回客户端。我是否遗漏了一条防止 500 被破坏的指令?

TIA

Heyas. I'm using mod_proxy with apache2 provide vhost ability to multiple servlet apps running on the local machine. It works fine, for the most part. Requests come into apache then are directed to the application bound on a port on localhost. The app receives the request and responds, which is delivered back to the client by apache.

The problem I'm having is that the application delivers 500's on errors, and mod_proxy stomps on them. Often these errors are caused in a ajax request and the error is handled in client side javascript. For example, a call to a server side createObject(name) might throw a NameNotUniqueException , which is delivered back as a 500. The client javascript might then display an appropriate error message.

When an error is thrown by the application (resulting in a 500 response to mod_proxy), then apache stomps the error message and returns

500 Internal Server Error

Internal Server Error

The server encountered an internal error or
misconfiguration and was unable to complete
your request.

.. the stock apache server side error message.

I want mod_proxy to pass the original 500 back through to the client. Is there a directive I've missed which prevents clobbering of the 500?

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆悲凉 2024-09-02 20:00:07

您是否已将

 ProxyRequests Off
 ProxyErrorOverride Off
 ProxyPass /path/ http://backend.ip/path/
 ProxyPassReverse / http://backend.domain/

backend.ip 和 backend.domain 替换为您的值(我在这里使用 backend.ip,因为它阻止 apache 对每个请求运行 dns 查询)。

通常错误会按原样报告。因为ProxyErrorOverride默认是关闭的。如果我的配置没有发生这种情况,请检查 500 是否确实来自您的后端服务器。或者只是向我们展示您完整的代理配置。

Do you have

 ProxyRequests Off
 ProxyErrorOverride Off
 ProxyPass /path/ http://backend.ip/path/
 ProxyPassReverse / http://backend.domain/

Replace backend.ip and backend.domain with your values (i am using backend.ip here as it prevents apache from running dns queries on each request).

Usually errors are reported as is. Because ProxyErrorOverride defaults to off. If this doe not happen with my configuration, please check if the 500 is really from your backend server. Or just show us your complete proxy configuration.

暮凉 2024-09-02 20:00:07

我有同样的问题,自从从 apache2/mod_wsgi 更改为 apache2 并反向代理到 mod_wsgi-express 后,出现了 500 个空白页面。

我的配置(用 www.example.com 替换实际域):

<VirtualHost *:443>
  ServerName www.example.com

  ProxyRequests Off
  ProxyErrorOverride Off
  ProxyPass         /  http://localhost:8001/
  ProxyPassReverse  /  https://www.example.com/
  ProxyPreserveHost On
  RequestHeader set X-Forwarded-Proto "https"

  ErrorLog /var/log/apache2/www.example.com.error.log
  LogLevel warn
  CustomLog /var/log/apache2/www.example.com.log combined

  SSLEngine On
  SSLCertificateFile    /etc/letsencrypt/live/www.example.com/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
  SSLCertificateChainFile       /etc/letsencrypt/live/www.example.com/fullchain.pem
</VirtualHost>

I have the same problem, getting a blank 500 pages since changing from apache2/mod_wsgi to apache2 with reverse proxy to mod_wsgi-express.

My config (replaced actual domain with www.example.com):

<VirtualHost *:443>
  ServerName www.example.com

  ProxyRequests Off
  ProxyErrorOverride Off
  ProxyPass         /  http://localhost:8001/
  ProxyPassReverse  /  https://www.example.com/
  ProxyPreserveHost On
  RequestHeader set X-Forwarded-Proto "https"

  ErrorLog /var/log/apache2/www.example.com.error.log
  LogLevel warn
  CustomLog /var/log/apache2/www.example.com.log combined

  SSLEngine On
  SSLCertificateFile    /etc/letsencrypt/live/www.example.com/cert.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
  SSLCertificateChainFile       /etc/letsencrypt/live/www.example.com/fullchain.pem
</VirtualHost>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文