Last active
September 8, 2023 03:17
-
-
Save nguyen127001/a502a1eb71777df6f9135303030ede8a to your computer and use it in GitHub Desktop.
Nginx - TCP load balancing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Địa chỉ file cấu hình: | |
/etc/nginx/passthrough.conf | |
``` | |
stream { | |
upstream nginxlb { | |
server IP1:PORT1 max_fails=3 fail_timeout=10s; # đổi IP PORT | |
server IP2:PORT2 max_fails=3 fail_timeout=10s; # đổi IP PORT | |
} | |
log_format basic '$remote_addr [$time_local] ' | |
'$protocol $status $bytes_sent $bytes_received ' | |
'$session_time "$upstream_addr" ' | |
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"'; | |
access_log /var/log/nginx/nginxlb_access.log basic; | |
error_log /var/log/nginx/nginxlb.biz_error.log; | |
server { | |
listen PORT; # đổi PORT cần | |
proxy_pass nginxlb; | |
proxy_next_upstream on; | |
} | |
} | |
``` | |
# Sau khi chỉnh sửa dùng lệnh này để verify cấu hình nginx | |
``` | |
sudo nginx -t | |
``` | |
# Reload - không làm mất kết nối | |
``` | |
sudo nginx -s reload | |
``` | |
# Restart | |
``` | |
sudo systemctl restart nginx | |
``` | |
# Stop | |
``` | |
sudo systemctl stop nginx | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment