Loading... # 引言 这里的端口转发并不是说反向代理,比如说通过nginx代理MySQL。 # 网络环境 ![image.png](https://www.zunmx.top/usr/uploads/2022/12/546598360.png) 此时不能直接通过3306连接数据库,然而通过nginx做了代理,以localhost的名义访问MySQL,这样就可以了。 # nginx.conf ```properties stream { server{ listen 33063; proxy_connect_timeout 5s; proxy_timeout 30s; proxy_pass 172.18.52.151:3306; } } ``` 或者这样定义 ```properties 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 /var/log/nginx/access.log proxy; upstream mysql_server { server 172.18.52.151:3306; } server { listen 8306; proxy_pass mysql_server; } } ``` ![image.png](https://www.zunmx.top/usr/uploads/2022/12/4040574923.png) ![image.png](https://www.zunmx.top/usr/uploads/2022/12/3132564646.png) © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏