【发布时间】:2016-04-29 22:32:49
【问题描述】:
我已经在centos7(来自aws的ec2-instance)上安装了nginx+mysql+nodejs。 一个简单的节点应用程序工作正常。它可以通过 curl 和 Web 浏览器访问。但是一个简单的快速应用程序不能通过 webbrowser 运行(响应 502)。它只能通过 curl http://MY-PRIVATE-IP:8080 工作。 在我本地安装的服务器上,每个想法都很好。 注意:我没有安装 express global。可能是m。搞错了?
有什么想法吗?我会很感激你的想法。谢谢。
这里是关于我的 nginx 配置和节点应用程序的详细信息:
nginx.conf
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
#worker_rlimit_nofile 30000;
events {
worker_connections 1024;
}
http {
index index.php index.htm index.html;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
types_hash_max_size 2048;
gzip on;
#include /etc/nginx/conf.d/*.conf;
upstream node_upstream {
server MY-PRIVATE-IP:8080;
}
server_tokens off;
server {
listen 80;
listen [::]:80;
server_name _;
root /var/www/html;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
location /myapp {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://node_upstream;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
nodejs 应用:hallo.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hallo Welt\n');
}).listen(8080, 'MY-PRIVATE-IP');
console.log('Server running at http://MY-PRIVATE-IP:8080/');
expressjs 应用:hello.js
var express = require('express');
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
app.listen(8080, function () {
console.log('Example app listening on port 8080!');
});
【问题讨论】: