前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx简单的负载均衡配置

nginx简单的负载均衡配置

作者头像
用户2603479
发布2018-08-16 10:04:37
2890
发布2018-08-16 10:04:37
举报
文章被收录于专栏:JAVA技术站JAVA技术站
代码语言:javascript
复制
nginx配置如下
代码语言:javascript
复制
#user  nobody;
#启动进程,通常设置成和CPU的数量相等
worker_processes  1;
#全局错误日志及PID文件
error_log  /var/log/nginx/error.log;
pid /var/run/nginx.pid;

#工作模式及连接数上限
events {
    use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种方式可能提高nginx性能
    worker_connections  1024;#单个后台worker process进程的最大的并发连接数
}

#设计http服务器,利用它的反向代理功能提供负载均衡支持
http {
    #设定minme类型,类型由mime.type文件定义
    include       mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] '
	'"$request" $status $bytes_sent '
	'"$http_referer" "$http_user_agent" '
	'"$gzip_ratio"';
	log_format download '$remote_addr - $remote_user [$time_local] '
	'"$request" $status $bytes_sent '
	'"$http_referer" "$http_user_agent" '
	'"$http_range" "$sent_http_content_range"';
	log_format post '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" $content_type $http_accept_encoding'
        '"$gzip_ratio" $request_body';
    #设计日志格式
   	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;
    #sendfile 指令指定nginx是否调用sendfile函数(zero copy方式)输出文件
	#必须调为on,如果用来下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
    sendfile        on;
    #tcp_nopush     on;
    #连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #设定请求缓冲
   	client_header_buffer_size 32k;
	large_client_header_buffers 4 32k;
	#开永嘉gzip压缩
	gzip on;
	gzip_min_length 1100;
	gzip_buffers 4 8k;
	gzip_types text/plain text/css application/x-javascript application/json; 
	output_buffers 1 32k;
	postpone_output 1460;
	#设定负载均衡的服务器列表,backup代表备份服务器,只有当所有节点都没有返回时,才启用http://hillside.iteye.com/blog/703281
    upstream zxSrv{
		server 127.0.0.1:8080;
		server 127.0.0.1:8288;
	}
    server {
	    #侦听80端口
        listen       80;
		#侦听域名
        server_name  www.ruijinzhuangxiu.com;
        #设置编码
        charset utf-8;
        #设置本虚拟机的访问日志
        access_log  /var/log/nginx/8088.log  main;
        #设置转发机置
        location / {
          proxy_pass http://zxSrv;
        }

        #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   127.0.0.1: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 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014/07/02 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档