502 Bad Gateway nginx/xxx
                                            
 7515 단어  Nginx
                    
한 번 혹은 여러 번 갱신 하면 됩 니 다.이게 무슨 이유 일 까요?
최근 nginx 의 에이전트, 부하 균형 기능 을 사용 해 이 문제 의 근본 원인 을 발견 했다.
무슨 이유?바로 백 엔 드 서비스 입 니 다. 끊 겠 습 니 다!
예제 설정 1:
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       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  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
	upstream tomcatserver1 {
	#3 tomcat  
		server 192.168.5.254:8001;
		server 192.168.5.254:8002;
		server 192.168.5.254:8003;
    } 
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
		
		location / {
            proxy_pass   http://192.168.5.254:8001; #     
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
  이러한 상황 에서 백 엔 드 서비스 가 끊 기 면 백 엔 드 서비스 가 회복 되 지 않 는 한 아무리 닦 아 도 소 용이 없습니다.
예제 설정 2:
#############           ############
#       ,   nobody nobody。
#user  nobody;
#        ,   1,       CPU   
worker_processes  1;
#      ,  。           ,http ,server ,     :debug|info|notice|warn|error|crit|alert|emerg
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#  Nginx        
pid        logs/nginx.pid;
events {
	
	#     ,   512
    worker_connections  1024;
}
http {
	#             
    include       mime.types;
	#      ,   text/plain
    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"';
	#combined         
    #access_log  logs/access.log  main;
	#  sendfile      ,   off,   http ,server ,location 。
    sendfile        on;
    #tcp_nopush     on;
	#      ,   75s,   http,server,location 。
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
	upstream tomcatserver1 {
	#3 tomcat  
		server 192.168.5.254:8001 weight=3;
		server 192.168.5.254:8002;
		server 192.168.5.254:8003;
    } 
    server {
		#    
        listen       8883;
		#    
        server_name  localhost;
		#         
		#client_max_body_size 1024M;
		
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
		
		location / {
            proxy_pass   http://tomcatserver1; #     
            index  index.html index.htm;
        }
        #location / {
        #    root   html;
        #    index  index.html index.htm;
        #}
        #error_page  404   /404.html;
		error_page 404   http://www.buchang.com;
		
		#   url  ,    ,~      ,~*       。
		#location  ~*^.+$ {       
        #   #root path;  #   
        #   #index vv.txt;  #     
        #   proxy_pass  http://mysvr;  #    mysvr         
        #   deny 127.0.0.1;  #   ip
        #   allow 172.18.5.54; #   ip           
        #} 
        # redirect server error pages to the static page /50x.html
        #
        #error_page   500 502 503 504  /50x.html;
        location ^~ /weixin_40205234 {
            proxy_pass https://blog.csdn.net/weixin_40205234;
        }
		location ^~ /index {
            proxy_pass http://www.buchang.com:3454/index;
        }
		
		location ^~ /DSWJ {
			rewrite ^/DSWJ/(.*)$ /DSWJ/$1 break;
			proxy_pass	http://192.168.6.5/DSWJ;
		}
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
  이 경우 부하 균형 을 사 용 했 습 니 다. 백 엔 드 에 N + 1 대의 서버 가 있 습 니 다. 방문 할 때마다 페이지 는 같 지만 방문 한 백 엔 드 서버 는 하나 가 아 닐 수 있 습 니 다. 이 경우 리 셋 을 통 해 문 제 를 해결 할 수 있 습 니 다.
물론 이 두 가지 상황 은 모두 Nginx 의 간단 한 설정 애플 리 케 이 션 일 뿐 백 엔 드 가 사용 가능 한 지 판단 하지 않 았 습 니 다. 백 엔 드 가 사용 가능 한 지 판단 하 는 설정 을 추가 하면 이 오 류 를 전혀 볼 수 없습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
linux2에 nginx 설치설치 가능한 nginx를 확인하고, 해당 nginx를 설치한다. localhost 혹은 해당 ip로 접속을 하면 nginx 화면을 볼 수 있다....
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.