編譯安裝Nginx
從1.9.0開始,nginx就支持對TCP的轉發,而到了1.9.13時,UDP轉發也支持了。提供此功能的模塊爲ngx_stream_core。不過Nginx默認沒有開啓此模塊,因此須要手動安裝html
1
2
3
4
5
6
|
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
TCP轉發
目標:經過3000端口訪問本機Mysql(其中mysql使用yum安裝,默認配置文件)mysql
/usr/local/nginx/conf/nginx.conf
配置以下:nginx
user nobody; worker_processes auto; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { use epoll; worker_connections 1024; } stream { server { listen 3000; proxy_pass 127.0.0.1:3306; 4# 也支持socket 4# proxy_pass unix:/var/lib/mysql/mysql.socket; } }
UDP轉發
目標: 發送UDP數據到3000端口,3001端口能夠接收sql
/usr/local/nginx/conf/nginx.conf
配置以下:socket
user nobody; worker_processes auto; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { use epoll; worker_connections 1024; } stream { server { listen 3000 udp; proxy_pass 127.0.0.1:3001; } }