nginx tcp代理並限制ip訪問
阿新 • • 發佈:2021-07-21
Nginx 從1.9.0開始釋出ngx_stream_core_module模組,該模組支援tcp代理及負載均衡。
本文記錄一下用nginx實現zk的代理並限制指定ip可以訪問
配置檔案
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/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"'; access_log /var/log/nginx/access.log main; sendfile on;#tcp_nopush on; keepalive_timeout 65; #gzip on; #geo $remote_addr $geo { # default 1; # include conf.d/whitelist.conf; #} include /etc/nginx/conf.d/*.conf; } stream{ #allow 127.0.0.1; #deny all; #也可以寫在檔案裡,用include匯入 include conf.d/whitelist.conf; upstream zk{ hash $remote_addr consistent; server127.0.0.1:2181 max_fails=3 fail_timeout=10s; } server{ listen 8182; proxy_connect_timeout 20s; proxy_timeout 5m; proxy_pass zk; } }