首页 > 代码库 > nginx 配置nginx.conf,负载均衡,逻辑分流

nginx 配置nginx.conf,负载均衡,逻辑分流

nginx 最重要的配置文件nginx.conf:一般的配置我不做解释,网上到处都是,主要对主要的几点进行注释(如下)worker_processes  8;error_log     /data/logs/nginx_error.log  crit;worker_rlimit_nofile 655350;events {        use epoll;        worker_connections      10240;}http {sendfile on;#tcp_nopush on; //这是不作缓冲数据的设置,对于play framework这种需要宽进快出的web-server construction 需要屏蔽掉#tcp_nodelay on;//同上keepalive_timeout 65;//超时时间types_hash_max_size 2048;limit_zone one $binary_remote_addr 10m;client_max_body_size 30m;include mime.types;default_type  application/octet-stream;        access_log    /data/logs/access.log;//以下是压缩相关配置gzip on;gzip_min_length 1000;gzip_buffers 4 8k;gzip_types text/plain application/x-javascript text/css application/xml;upstream web {server 127.0.0.1:8080;}//定义一组服务器upstream api {server 127.0.0.1:9000;                server 127.0.0.1:9003;}//定义一组服务器        upstream api1 {               server 10.200.57.155:9000;      server 127.0.0.1:9004;      }//.....upstream admin {server 127.0.0.1:9002;}.......//监听端口server {listen 443;ssl on;ssl_certificate /etc/ssl/cacert.pem;ssl_certificate_key /etc/ssl/privkey.pem;server_name api.fastooth.com;location / {   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   Refer        $http_referer;//根据请求的url进行分流,可以直接进行返回http status              if ( $uri ~* (.*)(location) ) {                   return 200;                   break;                }//根据请求的url进行分流,选择不同的服务器               if ( $uri ~* (.*)(dealMessage) ) {                    proxy_pass http://api1;                }if ( $uri ~* (.*)(runLog) ) {                    proxy_pass http://api1;                }   proxy_pass http://api;                   proxy_pass https://223.4.174.21;}}}

 

nginx 配置nginx.conf,负载均衡,逻辑分流