[英]Nginx 502 Bad Gateway error on EC2 Instance
我在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問題,但我找不到解決方案。 謝謝
遵循不同的方法。 允許您的應用程序在端口3000上運行(並同時監聽3000)。 在這種情況下,您必須將其打開為
HTTP:// URL:3000
現在,我們只需要將到達端口80的所有請求轉發到3000,這可以使用iptables輕松完成:
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000
現在,您應該可以簡單地使用網址打開它,而無需端口號
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.