我正在使用 pm2 为我的节点 js 应用程序提供服务。
nginx.conf 文件是
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
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;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
在 conf.d/
文件夹中,我创建了如下配置文件(名称为 api.conf)
server {
listen 80;
server_name dev.xxxxxxx.com;
underscores_in_headers on;
# return 301 https://$host$request_uri;
location / {
proxy_pass http://localhost:3004/;
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;
}
}
当我停止节点应用程序 nginx server the ELB Health status is 502
并在我启动 nginx 服务器时启动 nginx server the ELB Health status is 404
我无法找到问题所在。谁能帮我理解和解决
甚至我检查了 nginx 错误日志如下
[02/Feb/2021:17:21:29 +0000] "GET / HTTP/1.1" 502 157 "-" "ELB-HealthChecker/2.0" "-"
[02/Feb/2021:17:21:38 +0000] "GET / HTTP/1.1" 404 60 "-" "ELB-HealthChecker/2.0" "-"
设置运行状况检查时,ALB 不包含 HOST: 标头值。
如果您修改日志,您将看到 ELBHealthCheck 请求来自私有 IP 地址。
所以当 nginx 运行时,它会从一个不匹配任何服务器元素的私有 IP 获取请求。由于您没有设置 default_server,它默认为第一个,在这种情况下,它将是您的节点应用程序的代理。
/usr/share/nginx/html 中有文件吗?尝试将 index.html 放在那里,并将 default_server 添加到端口配置中: