【问题标题】:NodeJs on nginx not working without a port number in the url在 url 中没有端口号的情况下,nginx 上的 NodeJs 无法工作
【发布时间】:2015-05-07 20:56:50
【问题描述】:

我已经尝试了很多东西,我正在 nginx 服务器上使用 ExpressJS 运行 NodeJS 应用程序,只要我将 :3000 (或任何其他端口)添加到我的 url,一切正常

http://162.209.01.01:3000 显示正确的节点应用程序 http://162.209.01.01 显示 nginx 欢迎页面(欢迎使用 nginx,如果你看到这个页面...)

我想将端口 3000 映射到端口 80,这样我就可以加载节点应用程序,而无需在 url 中输入端口。

这是我的sites-enabled/default 文件:

upstream testApp {
server 127.0.0.1:3000;
    keepalive 64;
}

server {
    listen 80;
    server_name .testApp;
    access_log /var/log/nginx/simplyAsk.log;

    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For     
            $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass http://162.209.01.01;
            proxy_redirect off;
            proxy_http_version 1.1;
    }
}

这是我的bin/www 文件:

#!/usr/bin/nodejs
var debug = require('debug')('my-application');
var app = require('../app');

app.set('port', process.env.PORT || 3000);

var server = app.listen(app.get('port'), function() {
    debug('Express server listening on port ' + server.address().port);
});

【问题讨论】:

  • 你有奇怪的proxy_pass 指令。大概应该是proxy_pass http://testApp/;
  • 是的,这行得通,绝对不会猜到。谢谢!
  • 无需猜测。请小心并了解您编写/复制的内容……

标签: node.js express nginx port


【解决方案1】:

你的 proxy_pass 声明有点不对劲。

试试下面的。

proxy_pass http://testApp/;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-25
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多