API Rest Nginx无法获取

时间:2017-10-17 05:22:15

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

我使用Express和Node.js开发了一个API。我有一个简单的路由,需要将Nginx设置为反向代理(遵循以下步骤:https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04#set-up-nginx-as-a-reverse-proxy-server)但是当我创建GET请求时,我的浏览器会说:"无法获取/视频/ GetVideo / some_id&#34 ;

节点代码:

_apiRoutes = express.Router();
_apiRoutes.get('/video/GetVideo/:VideoID', (req, res) => {
    getVideo(req.params, (result) => {
        res.json(result);
    });
});

_apiRoutes.get('*', function (req, res) {
    res.status(404).send('yay!, are you lost?');
});

app.use('/api', _apiRoutes);

最后一段代码生成一条路线,如:http://some_url/api/video/GetVideo/:VideoID

Nginx代码:

    ... 
    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            #try_files $uri $uri/ =404;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header x-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://localhost:3500;
            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;

0 个答案:

没有答案