NodeJs on nginx not working without a port number in the url

爷,独闯天下 提交于 2019-12-23 04:00:33

问题


I have tried quite a few things already, I'm running a NodeJS app using ExpressJS on a nginx server, everything works as long as I add :3000 (or any other port) to my url

http://162.209.01.01:3000 displays the correct node app http://162.209.01.01 displays the nginx welcome page (Welcome to nginx, if you see this page...)

I want to map port 3000 to port 80 just so that I can load the node app without typing the port in the url.

This is my sites-enabled/default file:

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;
    }
}

This is my bin/www file:

#!/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);
});

回答1:


Your proxy_pass statement is a little off.

Try the following.

proxy_pass http://testApp/;



来源:https://stackoverflow.com/questions/30097334/nodejs-on-nginx-not-working-without-a-port-number-in-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!