nginx 健康检查配置
(1)upstream配置
check interval=1000 rise=2 fall=5 timeout=10000 type=http port=6002;
check_http_send "GET /info HTTP/1.0\r\n\r\n"; #注意这里检查可达的URL
check_http_expect_alive http_2xx http_3xx;
(2)location 配置
proxy_connect_timeout 90;
proxy_send_timeout 300;
proxy_read_timeout 300;
(3)生效日志
/logs/error.log 如果出现不可达该日志一直检测!
示例:
############################################################
# $Name: nginx.conf
# $Version: v1.0
# $Description: tengine配置
# #author chris
############################################################
#user nobody;
#user nginx;
worker_processes 4;
#worker_rlimit_nofile 8192;
events {
worker_connections 1024;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
#error_log logs/error.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
gzip on;
gzip_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/json;
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;
gzip_comp_level 6;
gzip_min_length 1024;
gzip_buffers 16 8k;
keepalive_timeout 60;
client_max_body_size 20m;
upstream api {
server 172.XX.XX.30:6002;
server 172.XX.XX.18:6002;
check interval=1000 rise=2 fall=5 timeout=10000 type=http port=6002;
check_http_send "GET /info HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
upstream fdfs {
server 172.16.0.9:22122;
}
#websocket配置
upstream wsbackend {
server 172.24.124.75:8080;
}
map $http_upgrade $connection_upgrade {
}
server {
listen 80;
server_name saas.test;
#access_log /usr/local/nginx/logs/saas.test/access.log main;
#error_log /usr/local/nginx/logs/saas.test/error.log;
location / {
root html;
index index.html index.htm;
}
#location /wechat {
# root html;
# wechat/index wechat/index.html wechat/index.htm;
#}
location /gi-saas-sd- {
proxy_pass http://api;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 90;
proxy_send_timeout 300;
proxy_read_timeout 300;
}
location /longhu- {
proxy_pass http://api;
}
location /customer-service- {
proxy_pass http://api;
}
location /zuul/ {
proxy_pass http://api;
}
location /group1/ {
proxy_pass http://fdfs;
}
#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 html;
}
}
}