简体   繁体   English

使用 Apache 的 mod_proxy 处理 POST 请求

[英]Handling POST requests using Apache's mod_proxy

I am currently hosting 2 web applications on the same Apache server.我目前在同一个 Apache 服务器上托管 2 个 web 应用程序。 Let's just call, them A and B. I was using JSONP to make cross domain ajax calls from A to B (I needed some data from B).让我们打电话给他们 A 和 B。我正在使用 JSONP 从 A 到 B 进行跨域 ajax 调用(我需要来自 B 的一些数据)。 The problem became apparent with this method when my request got too big and GET simply wouldn't work;当我的请求太大而 GET 根本不起作用时,这种方法的问题变得很明显; I needed to use a POST request.我需要使用 POST 请求。

I installed mod_proxy and configured my Apache web server to act as a reverse proxy as illustrated here: http://bit.ly/rpeWJI .我安装了 mod_proxy 并配置了我的 Apache web 服务器作为反向代理,如下所示: http://bit.ly/rpeWJI This worked beautifully with GET requests, but I am still unable to get POST requests to work properly.这与 GET 请求完美配合,但我仍然无法让 POST 请求正常工作。 Can someone help me?有人能帮我吗?

As a side note, I am using the Pylons web framework for my web applications.作为旁注,我正在为我的 web 应用程序使用 Pylons web 框架。

Do you have mod_security enabled in Apache?您是否在 Apache 中启用了 mod_security?

I came across your post while debugging why HTTP POST requests were failing against my reverse proxy.我在调试为什么 HTTP POST 请求对我的反向代理失败时遇到了你的帖子。 (They were receiving a 403 response). (他们收到了 403 响应)。

It turned our the server was using mod_security with OWASP settings.它使我们的服务器使用带有 OWASP 设置的 mod_security。 Monitoring the error log and then adding application/json to the list of approved types solved it.监控错误日志,然后将application/json添加到批准的类型列表中解决了它。

I also had to allow PUT requests for similar reasons.出于类似的原因,我还必须允许PUT请求。

May I suggest using nginx instead of Apache.我可以建议使用nginx而不是 Apache。 Here is an example config:是一个示例配置:

http {
    proxy_cache_path  /data/nginx/cache  levels=1:2    keys_zone=STATIC:10m
                                        inactive=24h  max_size=1g;
    server {
        location / {
            proxy_pass             http://1.2.3.4;
            proxy_set_header       Host $host;
            proxy_cache            STATIC;
            proxy_cache_valid      200  1d;
            proxy_cache_use_stale  error timeout invalid_header updating
                                  http_500 http_502 http_503 http_504;
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM