当前位置:快乐教育网 > 新闻频道 > 论文范文 >  windows2003下nginx均衡负载nginx.con

windows2003下nginx均衡负载nginx.con

发布时间:2019年01月15日 17:32:28  作者:快乐教育网  来源:网络整理  浏览:   【】【】【
配置负载均衡的目的是在于当用户访问我们的服务器的时候,下面我来给大家介绍在Nginx服务器nginx.conf详细负载均衡配置方法,希望对有需要的有所帮助。
1.nginx.conf配置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  crit;

# log  logs/error.log ;

#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;
    access_log      off;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;

    include header.conf;

    #keepalive_timeout  0;
    keepalive_timeout  65;
    include keepalive_timeout.conf;

    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 128k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_intercept_errors on;

    #gzip  on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 16 64k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary on;
    gzip_disable "MSIE [1-6].";

    server_names_hash_bucket_size 128;
    client_max_body_size     100m;
    client_header_buffer_size 256k;
    large_client_header_buffers 4 256k;

    include upstream.conf;
    include proxy.conf;
    include server.conf;
    include vhosts.conf;
}

2.header.conf配置
server_tokens  off;
add_header X-XSS-Protection "1; mode=block";

3.upstream.conf配置
upstream myhost {
    server 127.0.0.1:801 weight=1 max_fails=2 fail_timeout=30s;
    server 127.0.0.1:802 weight=1 max_fails=2 fail_timeout=30s;
}

4.proxy.conf配置

    proxy_temp_path "f:/nginx/temp/proxy_temp";
    proxy_cache_path "f:/nginx/temp/proxy_cache_path" levels=1:2 keys_zone=cache_one:50m inactive=1d max_size=1g;

    client_body_buffer_size 512k; 
    proxy_connect_timeout 60; 
    proxy_read_timeout 60; 
    proxy_send_timeout 60; 
    proxy_buffer_size 32k; 
    proxy_buffers 4 64k; 
    proxy_busy_buffers_size 128k; 
    proxy_temp_file_write_size 128k; 
    proxy_next_upstream error timeout invalid_header http_500 http_503 http_404; 
    proxy_cache cache_one; 

5.server.conf配置

server {
listen 80;
#START-ERROR-PAGE
error_page 403 /403.html;
error_page 404 /404.html;
error_page 502 /502.html;
error_page 503 /503.html;
#END-ERROR-PAGE
#PROXY-START
location / 
{
proxy_pass http://myhost;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
#proxy_cache_key $host$uri$is_args$args;
#proxy_cache_valid 200 304 12h;
#FILTER-START
proxy_set_header Accept-Encoding "";
sub_filter "屏蔽关键词" "替换关键词";
sub_filter_once off;
expires 2d;
#FILTER-END
}

}
#END-SITE
快速搜索 :