Nginx 负载均衡

nginx.conf

#user nobody;
worker_processes  4;
worker_rlimit_nofile 100000;
error_log logs/error.log;
pid        logs/nginx.pid;
events {
    worker_connections  2048;
    multi_accept on; 
    use epoll; 
  }


http {
    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 512m;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" $request_time" "$upstream_response_time"';
    access_log  /usr/local/nginx/logs/access.log main;
    server_tokens off; 
    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;
    keepalive_requests 100;
    keepalive_timeout  65;

    gzip  on;
    underscores_in_headers on;
    #gzip_static on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    gzip_http_version 1.1;
    gzip_comp_level 4;
    gzip_types text/plain application/x-javascript text/css  text/xml text/javascript application/x-httpd-php application/xml+rss application/json image/jpeg image/gif image/png;
 
    include /usr/local/nginx/conf/upstream_list/*.conf;
    include /usr/local/nginx/conf/servers/*.conf;
}

 

servers.conf

server {
    listen  80;
    server_name XXXXXX;
    index      index.jsp index.jspx index.html index.htm index.php;
    access_log logs/access;
    error_log   logs/err;

    location / {
        proxy_pass http://XXXX_backend;
        proxy_redirect off;
        proxy_set_header    Host    $http_host;
        proxy_set_header    X-Real-IP $remote_addr;
        proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }

    location = /favicon.ico {
          log_not_found     off;
          access_log     off;
    }

    error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
    }
}

 

upstream.conf

upstream XXXXXX_backend {
      ip_hash;
      server  10.5.0.61:80;
      server  10.5.0.XX:80;
      server  10.5.0.63:80;
      keepalive 20;
    }

 

posted @ 2021-01-15 17:41  tang88seng  阅读(126)  评论(1编辑  收藏  举报