[英]Expressjs failing to detect response
I'm trying to get my nodeapp working using express. 我正在尝试使我的nodeapp使用express。
I've setup a reverse proxy via nginx to use https://dank.ml/api/v1 but whenever I start up my app, it doesn't want to detect the / response. 我已经通过nginx设置了一个反向代理来使用https://dank.ml/api/v1,但是每当我启动我的应用程序时,它都不想检测/响应。
Here is my code: 这是我的代码:
var express = require('express');
var app = express();
var def = {'details': 'Running API v1.0'};
app.get('/', function(req, res) {
res.send('Home');
});
app.listen(8080);
console.log('API is now running on: 127.0.0.1:8080');
Here is my config: 这是我的配置:
server {
listen 80;
listen [::]:80;
index index.php index.html index.htm;
root /var/www/dank.ml/;
server_name dank.ml;
location /api/v1 {
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;
}
}
It's clearly saying 显然是在说
Cannot GET /api/v1
无法获取/ api / v1
ie the path passed to express is /api/v1 . 即传递到express的路径是/ api / v1 。
Use this config: 使用此配置:
location /api/v1/ {
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;
}
ie trailing slashes in both location
and proxy_pass
. 即在
location
和proxy_pass
中都使用斜杠。 source 资源
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.