带有nginx的socket.io-client - 用于POST的404失败了!为什么?

时间:2017-09-16 22:45:06

标签: nginx socket.io

我的应用程序在我的开发机器上工作正常,但当它移动到我的nginx服务器时,请参阅:

0|app      | ::ffff:127.0.0.1 - POST /socket.io-client/?EIO=3&transport=polling&t=LwCov_4 HTTP/1.1 404 157 - 0.344 ms
0|app      | POST /socket.io-client/?EIO=3&transport=polling&t=LwCov_4 404 0.344 ms - 157
0|app      | ::ffff:127.0.0.1 - GET /socket.io-client/?EIO=3&transport=polling&t=LwCowC_ HTTP/1.1 200 - - 1.045 ms
0|app      | GET /socket.io-client/?EIO=3&transport=polling&t=LwCowC_ 200 1.045 ms - -

其中所有GET都成功,所有POST都以404失败。

nginx配置的相关部分是:

location / {
   proxy_set_header   X-Real-IP $remote_addr;
   proxy_set_header   Host      $host;
   proxy_pass https://localhost:9000;
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header X-NginX-Proxy true;
   proxy_redirect https://xxxx.com:9000/ https://xxxx.com/;
}

location ~* \.io  {
   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 Connection "upgrade";

   proxy_pass https://localhost:9000;
   proxy_redirect off;

   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header X-NginX-Proxy true;
 }

快递作品有:

import { handleSocket } from './config/socketio';

let server = https.createServer(options, app);

let socketio = socket_io(server, {
   serveClient: localEnv.env !== 'production',
   path: '/socket.io'
});

server.listen(localEnv.port, () => {
   log('Express server listening on %d, in %s mode', localEnv.port, app.get('env'));
});

当跑步时:

2017-09-16T17:07:18-0400 app.js:192(Server。)Express服务器在生产模式下监听9000 除了针对socket.io POST&#39>的404以外,一切都有效

1 个答案:

答案 0 :(得分:0)

事实证明问题来自服务器上的一些未知问题。只需重新启动DigitalOcean上的Droplet即可解决问题。