【发布时间】:2018-09-07 19:22:00
【问题描述】:
我在 EC2 Linux 实例上配置 nginx 服务器时遇到了一些问题。我正在端口 3000 上运行一个应用程序,并希望使用 nginx 将其映射到端口 80。
这是我的配置文件:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
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;
top_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 128;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
index index.html index.htm
server {
listen 80 default_server;
[::]:80 default_server;
server_name localhost;
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location =/40x.html {
}
error_page 500 502 503 504 /50x.html;
location =/50x.html {
}
}
include /etc/nginx/sites-enabled/default;
这是 nginx 自带的默认文件,我做了非常细微的改动,最值得注意的是包含了一个名为 default 的自定义文件,其内容如下:
server {
listen 80;
server_name [my_domain_name];
location / {
proxy_pass http://[my_private_ip]:3000;
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;
}
}
将方括号中的项目替换为正确的值。每当我尝试导航到该网站时,我都会收到 502 Bad Gateway nginx/1.12.1。
我的服务器是运行在 3000 端口上的 node.js 服务器。
我已尝试排除故障并阅读有关不良网关的其他 stackoverflow 问题,但我无法找出解决方案。谢谢
【问题讨论】:
-
你能粘贴error.log吗
标签: node.js linux nginx amazon-ec2