nginx反向代理、负载均衡
#user nobody;
worker_processes 1;
events {
worker_connections 1024;
}
http{
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
include mime.types;
default_type application/octet-stream;
#上传文件大小
client_max_body_size 300m;
#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';
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 /logs/access.log main;
sendfile on;
keepalive_timeout 65;
fastcgi_connect_timeout 600;
upstream os-sx {
server 172.30.66.61:8080 weight=1;
server 172.30.66.62:8080 weight=1;
}
upstream os-v2 {
server 172.30.66.63:8080 weight=1;
server 172.30.66.64:8080 weight=1;
}
server {
listen 18080;
server_name 172.30.66.115;
#server_name jyyytest.19ego.cn;
#add_header Access-Control-Allow-Origin *;
#add_header Access-Control-Allow-Headers X-Requested-With;
#add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
location / { #添加访问目录为/apis的代理配置
proxy_connect_timeout 600s;
# add_header 'Access-Control-Allow-Origin' '*';
# rewrite ^/(.*)$ /$1 break;
#proxy_pass http://172.17.230.15:8086;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://os-sx;
}
}
server {
listen 18082;
server_name 172.30.66.115;
location / { #添加访问目录为/apis的代理配置
# rewrite ^/(.*)$ /$1 break;
# proxy_set_header Host $proxy_host;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://os-v2;
chunked_transfer_encoding off;
}
}
}