nginx 负载均衡配置
#user nginx;
worker_processes 1;
error_log /var/log/nginx/7dgroup-nginx_error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 2024 ;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent $request_time $upstream_response_time';
log_format json_log '{"client_ip":"$remote_addr","local_time":"$time_local","request":"$request","status":"$status","body_bytes_sent":"$body_bytes_sent","http_x_forwarded_for":"$http_x_forwarded_for","upstream_addr":"$upstream_addr","upstream_response_time":"$upstream_response_time","request_time":"$request_time"}';
access_log /var/log/nginx/nginx_access.log json_log;
sendfile on;
#tcp_nopush on;
# keepalive_timeout 65;
#gzip on;
upstream blog_test {
server 49.232.175.137:9001 weight=10 max_fails=2 fail_timeout=30s;
# server 172.17.211.143:9004 weight=10 max_fails=2 fail_timeout=30s;
keepalive 30;
# server 172.17.211.144:9004 weight=2 max_fails=2 fail_timeout=30s;
#设置持久连接时间。
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
#root /usr/share/nginx/html;
#index index.html index.htm;
proxy_http_version 1.1;
#开启对http1.1支持
proxy_set_header Connection "";
#设置Connection为空串,以禁止传递头部到后端
#keepalive 10;
proxy_pass http://blog_test;
}
#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 /usr/share/nginx/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;
#}
}
}