1

在使用 ng-flow、NodeJS 和 Express 进行开发时,我没有遇到任何问题,尽管我无法将 Nginx 正确配置为反向代理以使其与 ng-flow 和 Express 一起顺利运行。

在这里,您将找到一个处于待处理状态的请求示例:

Remote Address:192.168.0.81:80
Request URL:http://itl.lan/api/v1/flow-upload/
Request Method:POST
Status Code:200 OK
Response Headers
view source
Cache-Control:private, no-cache, no-store, must-revalidate
Connection:close
Date:Mon, 03 Aug 2015 20:24:56 GMT
Expires:-1
Pragma:no-cache
X-Powered-By:Express
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:en-US,en;q=0.8,it;q=0.6
App-Session-Hash:df9b1ac0-3a10-11e5-af61-af8fb284004c
Connection:keep-alive
Content-Length:1049741
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryY2FVUSE0oIcye77i
Host:itl.lan
Origin:http://itl.lan
Referer:http://itl.lan/webapp/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36
Request Payload
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowChunkNumber"

9
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowChunkSize"

1048576
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowCurrentChunkSize"

1048576
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowTotalSize"

12515925
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowIdentifier"

12515925-showcase_001_20150802T2239tgz
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowFilename"

showcase_0.0.1_20150802T2239.tgz
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowRelativePath"

showcase_0.0.1_20150802T2239.tgz
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="flowTotalChunks"

11
------WebKitFormBoundaryY2FVUSE0oIcye77i
Content-Disposition: form-data; name="file"; filename="showcase_0.0.1_20150802T2239.tgz"
Content-Type: application/x-compressed-tar

这是我在 NGINX server.conf 中的指令:

upstream itl_node_app {
    server 127.0.0.1:5000;
    keepalive 8;
}

server  {
...

    location /api/v1/flow-upload/ {
      proxy_set_header Access-Control-Allow-Origin *;
      proxy_set_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';
      proxy_set_header 'Access-Control-Allow-Headers' 'X-Requested-With,Accept,Content-Type, Origin$

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

检查 nginx error.log 你会发现:

2015/08/03 22:34:28 [error] 8004#0: *792 upstream sent no valid HTTP/1.0 header while reading response header from upstream, client: 192.168.0.4, server: itl.lan, request: "POST /api/v1/flow-upload/ HTTP/1.1", upstream: "http://127.0.0.1:5000/api/v1/flow-upload/", host: "itl.lan", referrer: "http://itl.lan/webapp/"

任何帮助表示赞赏。

干杯,卢卡

4

2 回答 2

1

NGINX 的日志说 HTTP 标头无效,请检查 express.js 上在此路由中定义的控制器:

/api/v1/flow-upload/

如果响应中发送的状态是一个数字。

我希望这有帮助!

于 2015-08-05T19:46:17.663 回答
0

我编写了 Express.js "/api/v1/flow-upload/" 路由作为模型和示例flow.js Node 示例应用程序,您可以在此处找到它。我描述的问题出现在第 23 行。status 参数可能是字符串文字。我了解到 Nginx 管理它的方式比 Express 更严格,从而引发了错误。

一个简单而安全的方法就是通过,例如:

res.status(200).send();
于 2015-08-05T21:29:15.117 回答