Nginx+Windows负载均衡配置方法负载均衡配置方法
一、下载一、下载Nginx
http://nginx.org/download/nginx-1.2.5.zip
解压到C:ginx目录下
二、在两台服务器上分别建一个网站:
S1:192.168.16.35:8054
S2:192.168.16.16:8089
二、找到目录二、找到目录
C:ginx\confginx.conf
打开nginx.conf
配置如下:
代码如下:
#使用的用户和组,window下不指定
#user nobody;
#指定工作衍生进程数(一般等于CPU总和数或总和数的两倍,例如两个四核CPU,则总和数为8)
worker_processes 1;
#指定错误日志文件存放路径,错误日志级别可选项为【debug|info|notice|warn|error|crit】
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
#指定pid存放路径
#pid logs/nginx.pid;
#工作模式及连接数上限
events {
#使用网络I/O模型,Linux系统推荐使用epoll模型,FreeBSD系统推荐使用kqueue;window下不指定
#use epoll;
#允许的连接数
worker_connections 1024;
}
#设定http服务器,利用他的反向代理功能提供负载均衡支持
http {
#设定mime类型
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;
log_format main ‘$remote_addr – $remote_user [$time_local]’
‘”$request” $status $bytes_sent’
‘”$http_referer” “$http_user_agent” “$http_x_forwarded_for”‘
‘”$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”‘;
#设定请求缓冲
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
#设定access log
access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 0;
keepalive_timeout 65;
#开启gzip模块
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain application/x-javascript text/css application/xml;
output_buffers 1 32k;