nginx负载均衡配置

负载均衡环境搭建,nginx.conf 配置文件内容记录一下。

worker_processes auto;
events {
worker_connections 1024;
}
http {
client_header_timeout 600;
client_body_timeout 600;
client_max_body_size 20m;
proxy_send_timeout 600;
proxy_read_timeout 600;

proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;


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"'
'$upstream_addr $upstream_response_time $request_time ';

access_log /nginx/logs/access.log main;
sendfile on;
keepalive_timeout 65;
#server_token off;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 8;
gzip_types text/plain application/javascript text/css application/json text/javascript image/svg+xml image/png;
gzip_vary off;

upstream testnginx {
#ip_hash;
sticky;
server ip:port weight=8 max_fails=1000 fail_timeout=10s;
server ip:port weight=8 max_fails=1000 fail_timeout=10s;
}

server {
listen 80;
server_name testnginx;

location / {
proxy_pass http://testnginx;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#add_headerCache-Control no-store;
}

#wf taskCount
location ^~ /api/runtime/task/v1.0/tasks/count {
proxy_pass http://testnginx/api/runtime/task/v1.0/tasks/count;
proxy_http_version 1.1;
proxy_read_timeout 3600s;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
}

posted @ 2021-05-24 22:33  小清澈  阅读(14)  评论(0)    收藏  举报