nginx做负载均衡的配置(简)

  1. #user  nobody;  
  2. worker_processes  1;  
  3.   
  4. #error_log  logs/error.log;  
  5. #error_log  logs/error.log  notice;  
  6. #error_log  logs/error.log  info;  
  7.   
  8. #pid        logs/nginx.pid;  
  9.   
  10.   
  11. events {  
  12.     worker_connections  1024;  
  13. }  
  14.   
  15. #标识http协议的一些日志格式和数据类型  
  16. http {  
  17.     include       mime.types;  
  18.     default_type  application/octet-stream;  
  19.   
  20.     log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  21.                       '$status $body_bytes_sent "$http_referer" '  
  22.                       '"$http_user_agent" "$http_x_forwarded_for"';  
  23.   
  24.     #access_log  logs/access.log  main;  
  25.   
  26.     sendfile        on;  
  27.     #tcp_nopush     on;  
  28.   
  29.     #keepalive_timeout  0;  
  30.     keepalive_timeout  65;  
  31.   
  32.     #gzip  on;  
  33.   
  34.       
  35.       
  36.     #服务器的集群 (就是负载的配置信息,请求来了之后需要nginx分发请求到哪些机器上)   
  37.     upstream  test-service {  #服务器集群名字,此处叫做 test-service   
  38.         server    192.168.13.227:9080;#服务器配置   weight是权重的意思,权重越大,分配的概率越大。  
  39.           
  40.         server    192.168.13.80:8080;   
  41.           
  42.     }   
  43.     #nginx服务器的监听ip和端口,使用的编码格式  
  44.     server {  
  45.         listen       80;  
  46.         server_name  192.168.13.80;  
  47.         charset utf-8;  
  48.         #charset koi8-r;  
  49.   
  50.         #access_log  logs/host.access.log  main;  
  51.   
  52.         #nginx的常用配置  
  53.         location / { #location代表拦截的请求路径/标识全部拦截  
  54.             proxy_pass http://test-service;  #固定格式标识负载到哪个upstream上,这里选择之前配置的test-service上.即http://test-service=http://+test-service  
  55.             proxy_redirect off;   
  56.               
  57.               
  58.             proxy_set_header        Host            $host;  
  59.             proxy_set_header        X-Real-IP       $remote_addr;  
  60.             proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;  
  61.             client_max_body_size    10m;  
  62.             client_body_buffer_size 128k;  
  63.             proxy_connect_timeout   3;  
  64.             proxy_send_timeout      30;  
  65.             proxy_read_timeout      30;  
  66.             proxy_buffer_size       128k;  
  67.             proxy_buffers           4 256k;  
  68.             proxy_busy_buffers_size 256k;  
  69.             proxy_temp_file_write_size  256k;  
  70.               
  71.               
  72.             #root   html;  
  73.             #index  index.html index.htm;  
  74.         }  
  75.   
  76.         #error_page  404              /404.html;  
  77.   
  78.         # redirect server error pages to the static page /50x.html  
  79.         #错误页面的跳转到哪些html上在nginx目录当中都是有的  
  80.         error_page   500 502 503 504  /50x.html;  
  81.         location = /50x.html {  
  82.             root   html;  
  83.         }  
  84.   
  85.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  86.         #  
  87.         #location ~ \.php$ {  
  88.         #    proxy_pass   http://127.0.0.1;  
  89.         #}  
  90.   
  91.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  92.         #  
  93.         #location ~ \.php$ {  
  94.         #    root           html;  
  95.         #    fastcgi_pass   127.0.0.1:9000;  
  96.         #    fastcgi_index  index.php;  
  97.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  
  98.         #    include        fastcgi_params;  
  99.         #}  
  100.   
  101.         # deny access to .htaccess files, if Apache's document root  
  102.         # concurs with nginx's one  
  103.         #  
  104.         #location ~ /\.ht {  
  105.         #    deny  all;  
  106.         #}  
  107.     }  
  108.   
  109.   
  110.     # another virtual host using mix of IP-, name-, and port-based configuration  
  111.     #  
  112.     #server {  
  113.     #    listen       8000;  
  114.     #    listen       somename:8080;  
  115.     #    server_name  somename  alias  another.alias;  
  116.   
  117.     #    location / {  
  118.     #        root   html;  
  119.     #        index  index.html index.htm;  
  120.     #    }  
  121.     #}  
  122.   
  123.   
  124.     # HTTPS server  
  125.     #  
  126.     #server {  
  127.     #    listen       443 ssl;  
  128.     #    server_name  localhost;  
  129.   
  130.     #    ssl_certificate      cert.pem;  
  131.     #    ssl_certificate_key  cert.key;  
  132.   
  133.     #    ssl_session_cache    shared:SSL:1m;  
  134.     #    ssl_session_timeout  5m;  
  135.   
  136.     #    ssl_ciphers  HIGH:!aNULL:!MD5;  
  137.     #    ssl_prefer_server_ciphers  on;  
  138.   
  139.     #    location / {  
  140.     #        root   html;  
  141.     #        index  index.html index.htm;  
  142.     #    }  
  143.     #}  
  144.   

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值