環(huán)境檢查
是否開啟 stream
nginx從1.9.0版本開始,新增了ngx_stream_core_module模塊,使nginx支持四層代理和負載均衡。
默認編譯時該模塊未編譯進去,需要編譯時添加 --with-stream,–with-stream_ssl_module,使其支持stream代理。
# 查看當前 Nginx 是否支持 stream 模塊
2>&1 nginx -V | tr ' ' '\n'|grep stream
# 說明支持 stream 模塊
--with-stream
編譯安裝Nginx
如果沒有安裝 Nginx
, 可以使用源碼編譯安裝的方式安裝 Nginx
, 并開啟 stream
模塊,編譯時如果相關編譯所需依賴沒有,centos 直接 yum 下載即可。文章來源:http://www.zghlxwxcb.cn/news/detail-410634.html
cd /usr/local/src
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-stream
make && make install
配置文件
以下為 Nginx
完整配置文件,分別監(jiān)聽 8080 端口轉發(fā) udp 服務和 7778 端口轉發(fā) tcp 服務。文章來源地址http://www.zghlxwxcb.cn/news/detail-410634.html
user root;
worker_processes auto;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#access_log logs/access.log;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 1024;
}
stream {
proxy_timeout 30s;
upstream udp_server {
server 127.0.0.1:20000;
}
log_format main '$remote_addr - [$time_local] '
' $status $bytes_sent ';
server {
listen 8080 udp;
proxy_pass udp_server;
#proxy_bind $remote_addr transparent;
access_log /usr
到了這里,關于Nginx代理TCP/UDP并測試的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!