前言

  • nginx 1.12.2
  • nginx从1.9.0开始,新增加了一个stream模块
  • nginx 安装参考这里
  • linux RedHat7

开启stream

修改/etc/nginx/nginx.conf

#增加stream配置,开启stream模块
stream {
    log_format basic '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time';
    access_log /var/log/nginx/stream-access.log basic buffer=32k;

    # 为了让这个配置文件简单一些,将配置stream放入到/etc/nginx/conf.d,并以.stream做后缀名。
    # 需要为每个端口创建一个.stream做后缀名的配置文件
    include /etc/nginx/conf.d/*.stream;
}

新增一个Stream代理

添加7000端口的stream代理配置。
新增配置/etc/nginx/conf.d/proxy_port7000_to_59.110.xxx.xxxp8001.stream

server{
    listen 7000;
    proxy_pass 59.110.xxx.xxx:8001;
}

重新加载配置

# 测试一下配置文件写的是否有问题
shell> nginx -t
# 配置文件没问题的话,重新加载配置
shell> nginx -s reload
Logo

更多推荐