在NGINX服务器上POST响应体为空

时间:2017-07-26 21:28:07

标签: node.js nginx nginx-reverse-proxy

我在带有SSL证书的NGINX服务器上运行Node.js应用程序。我刚刚意识到应用程序尝试返回前端的所有POST / PUT请求都是空的;本质上响应是一个空字符串。该应用程序在本地环境以及Heroku中运行良好,所有图像和GET请求都可以解决。

我期待JSON回到我的HTTP响应中,无论请求是成功还是有错误。现在我得到一个空字符串。下面是我的回复的屏幕截图,您会注意到内容长度标题完全丢失。

Screenshot of my headers

基本上,我的NGINX代理是否有问题阻止我的HTTP响应变回空白?

以下是我的NGINX配置文件

server {
    listen 80;

    server_name blah.com;
    rewrite ^/(.*) https://blah.com/$1 permanent;
}
server {
    # SSL configuration
    #
    listen 443 ssl default_server;
    ssl_certificate XXX;
    ssl_certificate_key XXX;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.html index.htm index.nginx-debian.html;

    server_name blah.com;

    location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
    }
}

Bellow是应用程序生成的访问日志:

24.123.110.242 - - [27/Jul/2017:21:10:45 +0000] "POST /sign-up         HTTP/1.1" 400 5 "https://app.quiqmath.com/sign-up" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36"
24.123.110.242 - - [27/Jul/2017:21:10:47 +0000] "POST /socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=Ls5upja&sid=4mrvSlNzMv9ZCetHAAAL HTTP/1.1" 502 182 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"
24.123.110.242 - - [27/Jul/2017:21:10:47 +0000] "GET /socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=Ls5ujej&sid=4mrvSlNzMv9ZCetHAAAL HTTP/1.1" 200 4 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"
24.123.110.242 - - [27/Jul/2017:21:10:48 +0000] "GET /socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=Ls5upzL HTTP/1.1" 200 101 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"
24.123.110.242 - - [27/Jul/2017:21:10:49 +0000] "GET /socket.io/?__sails_io_sdk_version=0.11.0&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=polling&t=Ls5up_l&sid=XSl8MUuC7TH6v4iLAAAM HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.1.2 Safari/603.3.8"

1 个答案:

答案 0 :(得分:1)

在版本大于0.11.X且小于1.0的Sails.js应用程序中,res.badRequest()响应在应用程序处于生产模式时将数据从响应中剥离。要解决此问题,请将Sails.js应用程序升级到1.X,将documentation can be found here升级为如何执行此操作,或者可以在api/responses/badRequest.js文件中注释掉以下行:

  // Only include errors in response if application environment
  // is not set to 'production'.  In production, we shouldn't
  // send back any identifying information about errors.
  if (sails.config.environment === 'production') {
    //data = undefined;
  }