首页 > 代码库 > Nginx作为反向代理支持5000并发---奇点时代

Nginx作为反向代理支持5000并发---奇点时代

user  nobody;

worker_processes 12;

error_log     logs/error.log;  ###/var/log/nginx/error.log;

pid           logs/nginx.pid;  ###/var/run/nginx.pid;

worker_rlimit_nofile  65535;


events {

    use  epoll;

    worker_connections    65535;

}


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; ### /var/log/nginx/access.log

 

       client_max_body_size 8m;

       client_header_buffer_size 32k;

       large_client_header_buffers 4 64k;    

       sendfile on; 

       tcp_nopush on;

       tcp_nodelay on;

       keepalive_timeout 120;


       gzip on;

       gzip_min_length 1k;

       gzip_buffers 4 16k;

       gzip_http_version 1.1;

       gzip_comp_level 2;

       gzip_types text/plain application/x-javascript text/css application/xml;

       gzip_vary on;

 

upstream localhost13914280{
     
      server 192.168.0.139:18080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:28080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:38080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:48080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:58080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:18080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:28080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:38080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:48080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:58080 weight=3 max_fails=2 fail_timeout=3s;
    }


#####First  virtual server

server {

        listen              80;

        server_name         192.168.0.137;

        access_log          logs/var/log/nginx/access.137.log;##/var/log/nginx/

       

        location  /  {

                    proxy_pass  http://localhost13914280;

                    proxy_next_upstream http_500  http_502 http_503 error timeout invalid_header;

                    include  /usr/local/nginx/conf/conf.d/*.conf;

                     }

        }

###########################################################################################

在137和138上建立conf.d目录。这样的做的目的是简化nginx配置文件。

 mkdir /usr/local/nginx/conf/conf.d/  &&  cd /usr/local/nginx/conf/conf.d

vi proxy.conf

  proxy_redirect off;

  proxy_set_header  Host $host;

  proxy_set_header  X-Real-IP  $remote_addr;

  proxy_set_header  X-Forward-For $proxy_add_x_forwarded_for;

  client_body_buffer_size  128k;

  proxy_connect_timeout  90;

  proxy_send_timeout 90;

  proxy_read_timeout 90;

  proxy_buffer_size 4k;

  proxy_buffers 4 32k;

  proxy_busy_buffers_size 64k;

  proxy_temp_file_write_size 64k;

###########################################################################################

                       

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

 }


###Second virtual server


 upstream localhost13480{
     
      server 192.168.0.134:18080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:28080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:38080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:48080 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:58080 weight=3 max_fails=2 fail_timeout=3s;
    }

        

server  {

               listen 80;

               server_name api.geekoin.com;

               access_log    logs/api.geekoin.com.log;

      

      location / {

                proxy_pass http://localhost13480;

                proxy_next_upstream http_500  http_502 http_503 error timeout invalid_header;

                    include  /usr/local/nginx/conf/conf.d/*.conf;

                     }       

     

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

}



upstream localhttps139142443{
     
      server 192.168.0.139:18443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:28443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:38443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:48443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.139:58443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:18443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:28443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:38443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:48443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.142:58443 weight=3 max_fails=2 fail_timeout=3s;

 }

server {
        listen       443;
        server_name  localhost;
        ssl on;
        ssl_certificate       server.crt;
        ssl_certificate_key   server.key;

      

     location / {

            proxy_pass https://localhttps139142443;

                proxy_next_upstream http_500  http_502 http_503 error timeout invalid_header;

            include  /usr/local/nginx/conf/conf.d/*.conf;

                    }


        }



upstream localhttps134443{
     
      server 192.168.0.134:18443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:28443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:38443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:48443 weight=3 max_fails=2 fail_timeout=3s;
      server 192.168.0.134:58443 weight=3 max_fails=2 fail_timeout=3s;
    }


server {

         listen  443;

         server_name api.geekoin.com;

         access_log    logs/api.geekoin.com.log;

     location / {

                proxy_pass http://localhttps134443;

                proxy_next_upstream http_500  http_502 http_503 error timeout invalid_header;

                    include  /usr/local/nginx/conf/conf.d/*.conf;

                     }       

     

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

}

}

       

 

本文出自 “常用文档” 博客,请务必保留此出处http://yujianglei.blog.51cto.com/7215578/1581584

Nginx作为反向代理支持5000并发---奇点时代