日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > Nginx >内容正文

Nginx

Nginx 端口转发实现!

發(fā)布時(shí)間:2023/12/20 Nginx 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。