手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

载均衡集群之Nginx

[日期:2014-03-30] 来源:Linux社区  作者:zhangxiaocen [字体:大 中 小]

Nginx 配置反向代理并对后端web Server 做健康状态监测

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

    worker_connections  1024;

}

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;

    sendfile        on;

    #tcp_nopush    on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

    #proxy_cache_path /nginx/cache levels=1:2 keys_zone=mycache:16m

#          inactive=24h max_size=1g;

    upstream backend {

        server 172.16.251.208:80;  # 后端web server 的ip地址

        server 172.16.251.244:80;

        server 172.16.251.191:80;

        healthcheck_enabled;  #启用此模块

        healthcheck_delay 1000; #对同一台后端服务器两次检测之间的时间间隔,单位毫秒,默认为1000;

        healthcheck_timeout 1000;  #进行一次健康检测的超时时间,单位为毫秒,默认值2000;

        healthcheck_failcount 1; # #对后端服务器检测失败多少次才能确认次服务器是不是挂掉了,相反服务器对后端服务监测成功了就将它写进可用的服务器列表中

        healthcheck_expected 'I AM_ALIVE';  # 期望从后端服务器请求什么样的内容如果未设置,则表示从后端服务器收到200状态码即为正确;

        healthcheck_send "GET /.health HTTP/1.0"; # 请求的页面在哪呀,使用http get方法请求 协议为1.0

        healthcheck_buffer##健康状态检查所使用的buffer空间大小;

}

}

    server {

        listen      80;

    server_name www.nginx.com ;

    location /  {

    proxy_pass http://backend;

    proxy_set_header Host $http_host;

    proxy_connect_timeout 3;

     

    }

          location / {

            healcheck_status;    # 通过类似stub_status的方式输出检测信息

        }

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page  500 502 503 504  /50x.html;

        location = /50x.html {

            root  html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass  http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root          html;

        #    fastcgi_pass  172.16.251.215:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen      8000;

    #    listen      somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen      443;

    #    server_name  localhost;

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

}

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款