Answer the question
In order to leave comments, you need to log in
Why does NGINX on a Linux server give a 502 error, while everything works without NGINX?
The application runs on express.js + socket.io + redis + mysql.
I posted the site for testing on a qa-stand (14.x ubuntu server).
Ubuntu has nginx 1.10.x.
I get a 502 Bad Gateway error. In the err log, nginx writes:
2017/02/14 00:50:31 [error] 11325#11325: *17 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.1, server: admin.mydomain.com, request: "POST /section /save HTTP/1.1", upstream: " 127.0.0.1:7103/section/save ", host: "admin.mydomain.com:7001", referrer: " admin.mydomain.com:7001/section/advertising/42 "
2017/02/14 00:50:31 [error] 11325#11325: *9 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.1, server: admin.mydomain.com, request: "GET /socket .io/?EIO=3&transport=polling&t=LevT9z1&sid=9Jg8IjXWdDWb_wZvAAAB HTTP/1.1", upstream: " 127.0.0.1:7103/socket.io/?EIO=3&transport=polling&... ", host:"admin.mydomain.com:7001", referrer: "admin.mydomain.com:7001/section/advertising/42 "
user www-data;
worker_processes 8;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
client_max_body_size 1024m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
server_tokens off;
access_log off;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
upstream nodes {
ip_hash;
server 127.0.0.1:7101;
server 127.0.0.1:7102;
server 127.0.0.1:7103;
server 127.0.0.1:7104;
server 127.0.0.1:7105;
server 127.0.0.1:7106;
server 127.0.0.1:7107;
server 127.0.0.1:7108;
}
server {
listen *:7001;
server_name admin.mydomain.com;
access_log off;
error_log /var/log/nginx/error.log;
location / {
auth_basic "Admin Zone";
auth_basic_user_file /mnt/sdb1/mydomain/.htpasswd;
proxy_pass http://nodes;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 180;
}
location ~* \.(jpg|jpeg|gif|png|webp|ico|css|bmp|swf|js|html|txt|ejs)$ {
root /mnt/sdb1/mydomain/admin/www;
expires max;
}
}
Answer the question
In order to leave comments, you need to log in
Is that clear?
location / {
try_files $uri @nodes;
}
location @nodes {
proxy_pass http://nodes;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question