【nginx】用stream模块实现TCP端口转发

一、实验目的

将本机的6033端口转发至本机3306

 

二、安装

# yum  -y install  maridb*  nginx

 

 三、配置

设置selinux为宽松模式

# setenforce 0

# sed -i 's/^SELINUX=.*/SELINUX=permissive/g'   /etc/selinux/config

 

# systemct start maridb

# systemct enable maridb 

# mysql_secure_installation

 

# vim  /etc/nginx/nginx.conf

####################################################

# For more information on configuration, see:

#   * Official English Documentation: http://nginx.org/en/docs/

#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

    worker_connections 1024;

}

stream {

    proxy_timeout 30m;

    server {

        listen 192.168.1.104:6033;

        proxy_pass 127.0.0.1:3306;

    }

}

######################################################

 

【nginx】用stream模块实现TCP端口转发_第1张图片

# systemctl  start nginx

# systemctl  enable nginx 

# systemctl  status  nginx

 

【nginx】用stream模块实现TCP端口转发_第2张图片

四、测试

#  mysql  -u root  -p"MySQL@123"

#  mysql  -u root -P 6033 -p"MySQL@123"

【nginx】用stream模块实现TCP端口转发_第3张图片

 

五、参考

 

nginx启用stream日志配置文件

https://www.cnblogs.com/cheyunhua/p/8823496.html

利用nginx的stream模块实现内网端口的转发代理

https://blog.51cto.com/icenycmh/2117844

Module ngx_stream_core_module

http://nginx.org/en/docs/stream/ngx_stream_core_module.html

Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理

https://cloud.tencent.com/developer/article/1027563

你可能感兴趣的:(docker,nginx)