如果没有网址中的端口号,nginx上的NodeJ将无法工作 [英] NodeJs on nginx not working without a port number in the url
问题描述
我已经尝试了很多事情,我正在nginx服务器上使用ExpressJS运行NodeJS应用,只要我在URL中添加:3000(或任何其他端口),一切都可以正常工作
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
显示正确的节点应用
http://162.209.01.01
显示nginx欢迎页面(欢迎访问nginx,如果您看到此页面...)
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...)
我只想将端口3000映射到端口80,以便可以加载节点应用程序而无需在url中键入端口.
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.
这是我的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/;
这篇关于如果没有网址中的端口号,nginx上的NodeJ将无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!