Nginx 端口转发实现!
生活随笔
收集整理的這篇文章主要介紹了
Nginx 端口转发实现!
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
題外話
如需轉(zhuǎn)載文章,請(qǐng)保留文章出處(knight.blog.csdn.net)。因?yàn)槲业暮芏辔恼乱话闶菚?huì)進(jìn)行更新的。也避免百度搜出來(lái)一大推相似的文章,卻找不到原創(chuàng)博主。
端口轉(zhuǎn)發(fā)的常見(jiàn)方式
- 通過(guò) Linux iptables實(shí)現(xiàn)
- HAProxy 實(shí)現(xiàn)(常見(jiàn))
- 通過(guò)Nginx的代理實(shí)現(xiàn)
- 等等(實(shí)現(xiàn)方式比較多,很多軟件能支持)
背景
最老版本的Nginx是不支持端口轉(zhuǎn)發(fā)的,稍微老一點(diǎn)的Nginx需要第三方軟件支持。新版本的Nginx是支持端口轉(zhuǎn)發(fā)的。我們采用的Nginx的版本如下:
$nginx -v nginx version: nginx/1.16.1安裝Nginx
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_ssl_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie' --with-http_stub_status_module --with-stream --with-stream_ssl_module端口轉(zhuǎn)發(fā)配置實(shí)現(xiàn)
Nginx的TCP端口轉(zhuǎn)發(fā)是通過(guò)?stream模塊 實(shí)現(xiàn)的。
我們想要通過(guò)Nginx的端口轉(zhuǎn)發(fā)功能實(shí)現(xiàn),將Nginx的6033端口轉(zhuǎn)發(fā)到某一個(gè)主機(jī)的mysql數(shù)據(jù)庫(kù)端口3306上。Nginx的配置文件如下:
# 本文博客地址: https://blog.csdn.net/caidingnu/article/details/90739915 ## events {use epoll;worker_connections 65535; } ## 端口轉(zhuǎn)發(fā)到mysql數(shù)據(jù)庫(kù) stream {proxy_timeout 30m;server {listen 10.19.193.223:6033;proxy_pass 10.19.2.198:3306; } }查看:
[root@hosname conf]# netstat -ntlp|grep nginx tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 23990/nginx: master tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 23990/nginx: master tcp 0 0 10.19.2.198:60022 0.0.0.0:* LISTEN 23990/nginx: master?
總結(jié)
以上是生活随笔為你收集整理的Nginx 端口转发实现!的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: css高度坍塌
- 下一篇: Nginx端口转发简明配置