nginx配置
nginx.conf
#user webmaster webmaster; worker_processes 8; worker_rlimit_nofile 51200; error_log logs/nginx_error.log crit; #pid logs/nginx.pid; events { use epoll; worker_connections 100000; } http { include mime.types; default_type application/octet-stream; server_names_hash_bucket_size 128; log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent post:$request_body "$http_referer" ' '"$http_user_agent" $request_time'; #sendfile on; tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 20; tcp_nodelay on; client_header_timeout 3m; client_body_timeout 3m; send_timeout 3m; connection_pool_size 256; client_header_buffer_size 1k; #large_client_header_buffers 4 2k; request_pool_size 4k; output_buffers 4 32k; postpone_output 1460; client_max_body_size 10m; client_body_buffer_size 256k; gzip off; gzip_min_length 1k; gzip_buffers 4 8k; gzip_http_version 1.0; gzip_types text/plain application/x-javascript text/css application/xml; #gzip_vary on; #避免重复请求,nginx不响应 499 proxy_ignore_client_abort on; access_log on; #log_format main '$status|$time_local|http://$host$request_uri|$remote_addr|$http_x_forwarded_for|$http_referer|$http_user_agent|$request_body'; log_format main '$status|$time_local|http://$host$request_uri|$remote_addr|$http_x_forwarded_for|$http_user_agent|$upstream_addr|$upstream_response_time|$request_time'; include vhost/vhost_*.conf; }
a.test.com.conf
upstream api.test.com { server 127.0.0.1:8084 ; } server { listen 80; server_name a.test.com b.test.com; index index.html index.htm index.jsp; root /letv/web/a.test.com; proxy_buffer_size 4k; proxy_buffers 16 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_read_timeout 180; access_log /letv/logs/nginx/api.pv.log main; location ~ \.rar$ { deny all; } location / { proxy_pass http://a.test.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } #指定参数跳转 location ~ .*/ip.do?$ { if ( $args ~* "type=a" ) { proxy_pass http://10.180.151.70:8084; } proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://127.0.0.1:8084; add_header Vary Accept-Encoding; } location /html{ root /data/logs ; } }
切换脚本 nginx-flow-swith.sh
if [ $# -eq 0 ];then echo "args not null or illegal"; echo "please input 149 150 156 157" else server_args="" for i in $@;do if [ $i -eq 149 ]; then server_args="$server_args server 10.100.54.149:8084;" elif [ $i -eq 150 ]; then server_args="$server_args server 10.100.54.150:8084;" elif [ $i -eq 156 ]; then server_args="$server_args server 10.180.153.156:8084;" elif [ $i -eq 157 ]; then server_args="$server_args server 10.180.153.157:8084;" else echo "server ip illegal"; exit 0; fi done if [ "$server_args" = "" ]; then echo "server ip illegal"; else echo $server_args sed "1a $server_args" /data/web/nginx_boss/conf/vhost_api.boss.letv.conf.template > /data/web/nginx_boss/conf/vhost/vhost_api.boss.letv.com.conf /data/web/nginx_boss/sbin/nginx -t -c /data/web/nginx_boss/conf/nginx.conf /data/web/nginx_boss/sbin/nginx -s reload -c /data/web/nginx_boss/conf/nginx.conf echo "nginx switch ok" fi fi
执行 sh nginx-flow-swith.sh 149 156
1a 表示在第一行后面追加
相关推荐
小木兮子 2020-11-11
nginxs 2020-11-14
Guanjs0 2020-11-13
yserver 2020-11-11
ssihc0 2020-11-11
windle 2020-11-10
HanksWang 2020-11-10
liuchen0 2020-11-10
Freshairx 2020-11-10
ccschan 2020-11-10
liwf 2020-11-10
Guanjs0 2020-11-09
AderStep 2020-11-09
zrtlin 2020-11-09
mqfcu 2020-11-10
windle 2020-10-29