【问题标题】:Why does NGINX reverse proxy $.ajax post give "net::ERR_CONNECTION_REFUSED"为什么 NGINX 反向代理 $.ajax post 给出“net::ERR_CONNECTION_REFUSED”
【发布时间】:2017-04-02 17:14:41
【问题描述】:

我在等待 xhr 响应时收到“net::ERR_CONNECTION_REFUSED”。 我试过使用 api 直接,它工作正常。我收到我的回复。此外,当通过 nginx 反向代理使用它时,我的 api 实际上会收到 POST,但 jquery 没有得到任何回复。就像我说的,使用http://ip:port.. 时会这样。

我的 nginx 配置如下所示:

upstream daffy {
    server 127.0.0.1:4747;
}

server {
    listen 80;
    server_name daffy;

    access_log  /var/log/nginx/daffy.access.log;
    error_log   /var/log/nginx/daffy.error.log;

    location /socket.io {
        proxy_pass http://daffy/socket.io;
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }

    location /git/pull/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_redirect off;
        proxy_set_header    X-Forwarded-Proto https;
        proxy_set_header Host $http_host;
        proxy_pass http://daffy;
    }

    location / {
        allow   192.168.7.0/24;
        deny    all;

        proxy_pass http://daffy;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
}

Nginx 在错误日志中没有显示错误。但访问日志根本没有记录 POST 请求。

nginx-1.11.12-1.el7.ngx.x86_64

有人有什么建议吗?

更新 我已尝试禁用防火墙并在错误日志中打开调试。

Nginx 并没有真正在错误日志中提供任何调试信息。

但是 GET 工作得很好:

192.168.7.114 - - [02/Apr/2017:09:54:02 +0200] "GET /users/?_=1491119642698 HTTP/1.1" 200 570 "http://daffy/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"

SELinux 已禁用。

【问题讨论】:

    标签: ajax post nginx proxy reverse


    【解决方案1】:

    已解决!!

    我不得不更改我的 python 后端以比 2 秒快一点:

    Popen(["/path/to/awesome.sh"], stdin=None,stdout=None,stderr=None)
    

    在我使用subprocess.check_callsubprocess.call 之前

    不管怎样,我从 api 中缩短了 2 秒的返回时间 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 2023-03-24
      • 2018-04-15
      • 1970-01-01
      • 2019-06-06
      • 1970-01-01
      • 2020-11-28
      相关资源
      最近更新 更多