快递无法在Nginx

时间:2017-10-24 16:59:29

标签: node.js express nginx

我已将此代码保存在我的Nginx服务器上,并使用加密SSL。

我对此代码的意图是成为后端服务器。



app.use(bodyParser.urlencoded({ extended: true }));

app.get('/', function(res, req) {
  res.send('GET ROOT');
});

app.post('/', function(res, req) {
  res.send('POST ROOT');
});

app.listen(port, () => {
  console.log('We are live on ' + port);
});




该代码在本地运行良好。

但是当我在远程服务器上部署它时,首先我请求GET example.com/它返回GET ROOT。然后我做了POST example.com/它返回GET ROOT。它应该是POST ROOT

这是我sites-available

的服务器配置代码段



server {
  listen 80 default_server;
  listen[::]: 80 default_server;

  server_name example.com;

  location / {
    proxy_pass http://localhost:3000;
    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;

  }

  # some ssh default path
}




服务器使用域成功传播,我认为加载index.html或具有GET功能的东西没有问题。我在这个开发阶段用nodemon运行js。

请建议..

我认为这是关于CORS的,我把默认的CORS配置,但仍然没有改变。 然后我添加此post函数,而不是get具有相同的端点。



app.post('/post', (req, res) => {
  res.send('POST POST');
});




它返回了这个结果



<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <title>Error</title>
</head>

<body>
  <pre>Cannot GET /post</pre>
</body>

</html>
&#13;
&#13;
&#13;

当我执行GET和POST请求时从Nginx错误日志(从/var/log/nginx/error.log.1检索)

&#13;
&#13;
2017/10/24 16:27:19 [error] 1667#1667: *14 connect() failed (111: Connection refused) while connecting to upstream, client: 125.163.124.227, server: officially.id, request: "GET $
2017/10/24 20:52:06 [error] 1667#1667: *72 connect() failed (111: Connection refused) while connecting to upstream, client: 94.23.35.126, server: officially.id, request: "GET / H$
2017/10/24 21:43:26 [notice] 2556#2556: signal process started
2017/10/24 21:48:01 [error] 2758#2758: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 114.124.167.30, server: officially.id, request: "GET /t$
2017/10/24 21:57:04 [notice] 2877#2877: signal process started
2017/10/24 22:00:30 [emerg] 2919#2919: invalid value "=" in /etc/nginx/sites-enabled/default:53
2017/10/24 22:00:39 [emerg] 2924#2924: invalid value "=" in /etc/nginx/sites-enabled/default:53
2017/10/24 22:10:15 [notice] 3060#3060: signal process started
2017/10/25 03:34:42 [error] 3063#3063: *36 connect() failed (111: Connection refused) while connecting to upstream, client: 71.6.202.198, server: officially.id, request: "GET /xx$
&#13;
&#13;
&#13;

当我尝试捕获app.js错误并输出时,除app.listen(...)处记录的字符串外,没有任何内容写入。

0 个答案:

没有答案