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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Nginx >内容正文

Nginx

Nginx 端口转发实现!

發布時間:2023/12/20 Nginx 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Nginx 端口转发实现! 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題外話

如需轉載文章,請保留文章出處(knight.blog.csdn.net)。因為我的很多文章一般是會進行更新的。也避免百度搜出來一大推相似的文章,卻找不到原創博主。

端口轉發的常見方式

  • 通過 Linux iptables實現
  • HAProxy 實現(常見)
  • 通過Nginx的代理實現
  • 等等(實現方式比較多,很多軟件能支持)

背景

最老版本的Nginx是不支持端口轉發的,稍微老一點的Nginx需要第三方軟件支持。新版本的Nginx是支持端口轉發的。我們采用的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

端口轉發配置實現

Nginx的TCP端口轉發是通過?stream模塊 實現的。

我們想要通過Nginx的端口轉發功能實現,將Nginx的6033端口轉發到某一個主機的mysql數據庫端口3306上。Nginx的配置文件如下:

# 本文博客地址: https://blog.csdn.net/caidingnu/article/details/90739915 ## events {use epoll;worker_connections 65535; } ## 端口轉發到mysql數據庫 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

?

總結

以上是生活随笔為你收集整理的Nginx 端口转发实现!的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。