Nginx 配置TCP代理轉(zhuǎn)發(fā)的實(shí)現(xiàn)
使用Nginx 新版的 stream方式,實(shí)現(xiàn)TCP/UDP代理轉(zhuǎn)發(fā)。
在Nginx安裝了 stream 模塊后。
修改nginx.conf
在主配置文件下 nginx.conf 增加 stream配置。
如 nginx home 為 /opt/software/nginx
cd /opt/software/nginx/conf vim nginx.conf
增加如下配置
stream {
log_format proxy '$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 /opt/software/nginx/logs/tcp-access.log proxy ;
open_log_file_cache off;
# 統(tǒng)一放置,方便管理
include tcpConf/*.conf;
}
增加stream配置
創(chuàng)建tcp配置文件夾,方便以后統(tǒng)一管理配置文件:
cd /opt/software/nginx/conf mkdir tcpConf
創(chuàng)建配置文件
cd tcpConf vim tcp9004.conf
編輯如下:
upstream tcp9004 {
server 118.178.188.188:8992;
}
server {
listen 9004;
proxy_connect_timeout 8s;
proxy_timeout 24h;
proxy_pass tcp9004;
}
測(cè)試重啟Nginx
測(cè)試Nginx
cd /opt/software/nginx ./sbin/nginx -t
沒(méi)有問(wèn)題之后
重啟Nginx
./sbin/nginx -s reload
端口監(jiān)聽(tīng)
使用tcpdump監(jiān)聽(tīng)tcp數(shù)據(jù)
安裝tcpdump
yum install -y tcpdump
查看網(wǎng)卡
ifconfig
監(jiān)聽(tīng)對(duì)應(yīng)網(wǎng)卡上的端口
tcpdump -n -v -i eth1 port 8992
到此這篇關(guān)于Nginx 配置TCP代理轉(zhuǎn)發(fā)的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx TCP代理轉(zhuǎn)發(fā)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解nginx實(shí)現(xiàn)ssl反向代理實(shí)戰(zhàn)
本篇文章主要介紹了nginx實(shí)現(xiàn)ssl反向代理實(shí)戰(zhàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01
Nginx設(shè)置日志打印post請(qǐng)求參數(shù)的方法
這篇文章主要介紹了Nginx設(shè)置日志打印post請(qǐng)求參數(shù)的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
nginx結(jié)合openssl實(shí)現(xiàn)https的方法
這篇文章主要介紹了基于nginx結(jié)合openssl實(shí)現(xiàn)https的方法,準(zhǔn)備工作大家需要安裝nginx服務(wù),具體操作過(guò)程跟隨小編一起看看吧2021-07-07
nginx: [warn] "log_format" directive used only on "http" lev
這篇文章主要介紹了nginx: [warn] "log_format" directive used only on "http" level 解決方法,需要的朋友可以參考下2014-08-08
nginx配置ssl證書實(shí)現(xiàn)https訪問(wèn)的示例
這篇文章主要介紹了nginx配置ssl證書實(shí)現(xiàn)https訪問(wèn)的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03

