nginx主动健康检查负载均衡模块
下载模块,放到源代码根目录:
重新安装:
./configure --add-module=./nginx_upstream_check_module --with-http_ssl_module --with-http_v2_module --with-stream --with-http_gzip_static_module
#默认安装到/usr/local/nginx下面
make
sudo make install
#查看版本(可看到所有编译进去的模块)
/usr/local/bin/nginx -V

#安装到全局(看自己的目录)
cp /usr/sbin/nginx /usr/local/bin/nginx.bak
cp ./objs/nginx /usr/local/bin/nginx
使用方法:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
error_log logs/error.log;
sendfile on;
client_max_body_size 100m;
client_header_timeout 300s;
client_body_timeout 300s;
gzip on;
gzip_static on;
upstream crmapi{
server 127.0.0.1:8002;
server 127.0.0.1:9002;
# Enable health checks
check interval=3000 rise=2 fall=2 timeout=2000 type=http;
# HTTP settings for health checks
check_http_send "GET /api/health HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
listen 443 ssl;
server_name _;
root /usr/local/nginx/html;
location / {
try_files $uri $uri/ /index.html;
}
ssl_certificate /usr/local/nginx/ssl/xxx.pem;
ssl_certificate_key /usr/local/nginx/ssl/xxx.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location /crm/ {
proxy_pass http://crmapi/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
#proxy-end====================================
}
}

============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · vue3+vite+多环境发面到二级目录配置
- · nginx http转https, 不带www转带www
- · nginx自动切换到手机/PC 网站
- · 使用tengine代替Nginx
- · nginx添加nginx_upstream_check_module
- · nginx上传文件超出默认大小限制,提示:413 Request Entity Too Large
- · nginx反向代理禁用缓存
- · docker nginx
- · consul+nginx完成集群服务动态发现和健康检查
- · nginx使用stream模块做ssh转发
- · nginx反向代理wss
- · nginx+keepalive负载均衡高可用
