nginx 负载均衡 例子

[root@XWBizEngine03 conf]# cat nginx.conf |egrep -v '#'  |grep -v '^$'
user  root;
worker_processes  auto;
error_log  logs/error.log debug;
events {
    worker_connections  4096;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
   log_format  main   '$remote_addr [$time_local] '
                    
                      '"$request" $request_time $body_bytes_sent $status "$http_referer" "$http_user_agent" ' 
                      '$upstream_addr $upstream_response_time $upstream_status'; 
access_log  /home/apaas/openrestylog/access.log  main;
    expires -1;
    sendfile        on;
    keepalive_timeout  300;
        client_max_body_size 64M;
    proxy_connect_timeout 300;
    proxy_read_timeout 300;
    proxy_send_timeout 300;
    gzip  on;
    gzip_http_version 1.0;
    gzip_min_length  102480;
    gzip_buffers     4 8k;
    gzip_types       text/plain application/x-JavaScript text/css application/xml application/json application/javascript application/octet-stream;
   
    include "/usr/local/openresty/nginx/conf/conf.d/all_upstream.conf";
    server {
        listen       48030;
            location / {
                 proxy_redirect off;
                 proxy_set_header  Host  $host;
                 proxy_set_header  X-Real-IP  $remote_addr;
                 proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
                 proxy_set_header  X-Forwarded-Proto $scheme;
                 proxy_connect_timeout 600s;
                 proxy_read_timeout 600s;
                 proxy_send_timeout 600s;
                 proxy_pass http://mybizserv;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
[root@XWBizEngine03 conf]# 
[root@XWBizEngine03 conf]# cat /usr/local/openresty/nginx/conf/conf.d/all_upstream.conf
upstream mybizserv {
    server 10.6.2.23:8030;
    server 10.6.2.23:8031;
    server 10.6.2.24:8030;
    server 10.6.2.25:8030;
}
[root@XWBizEngine03 conf]#

 

posted @ 2023-02-01 23:51  littlevigra  阅读(14)  评论(0编辑  收藏  举报