FreeBSD NGINX TCP转发

前几天搞转发,研究了下TCP转发,现在记录下来

首先加载模块

注意:这是FreeBSD的位置。并且需要NGINX支持

  • load_module /usr/local/libexec/nginx/ngx_stream_module.so;

该部分不属于http {}部分,不能写在里面

TCP转发

  • stream {
  • server {
  • listen 25565;
  • proxy_connect_timeout 5s;
  • proxy_timeout 20s;
  • proxy_pass 0.0.0.0:25565;
  • # socket 转发
  • # proxy_pass unix:/var/lib/mysql/mysql.socket;
  • }
  • }

UDP转发

  • stream {
  • server {
  • listen 233 udp;
  • proxy_pass 127.0.0.1:3366;
  • }
  • }

另外还有一个backlog参数

  • backlog=number
  • sets the backlog parameter in the listen() call that limits the maximum length for the queue of pending connections. By default, backlog is set to -1 on FreeBSD, DragonFly BSD, and macOS, and to 511 on other platforms.
  • 意思是FreeBSD, DragonFly BSD, and macOS平台默认为`-1`,其他,比如Linux,默认为`511`。

本文链接:https://www.moebsd.cn/post/NGINX—TCP.html

posted @ 2021-03-07 15:35  FreeBSD中文社区  阅读(65)  评论(0编辑  收藏  举报