nginx 配置stream模块代理并开启日志配置

前言

nginx从1.9.0开始,新增加了一个stream模块

确保nginx 安装时开启stream模块

./configure  
…… 
--with-stream 
--with-stream_ssl_module 

已安装的可以通过 nginx -V  查看已编译的模块

修改nginx.conf

#增加stream配置,开启stream模块

stream {
    log_format basic '$remote_addr [$time_local] '
                     '$protocol $status $bytes_sent $bytes_received '
                     '$session_time';
    access_log logs/stream-access.log basic buffer=32k;

    server{
        listen 6666;
        proxy_pass 10.11.11.11:7777;
    }
}

重新加载配置

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

示例仅供参考:

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/tcp-access.log  proxy;


    map $ssl_preread_server_name $backend_pool {
    	console.tim.qq.com    im;
		gateway.95516.com     yinlian;
        filedownload.95516.com yinlianfile;
    }
    upstream im{
    	server console.tim.qq.com:443;
    }
    upstream push{
    	server sdk.open.api.igexin.com:80;
    }
    upstream yinlian{
        server gateway.95516.com:443;
    }
    upstream yinlianfile{
        server filedownload.95516.com:443;
    }
    upstream zhongxin{
        server 202.99.22.131:30851;
    }
    upstream zhongxin2{
        server 219.142.124.178:30851;
    }
    server {
    	listen 443;
    	ssl_preread on;
    	resolver 114.114.114.114;
    	proxy_pass $backend_pool;
    	proxy_connect_timeout 15s;
    	proxy_timeout 15s;
    	proxy_next_upstream_timeout 15s;
    }
    server {
        listen 80;
        resolver 114.114.114.114 valid=3600s;
		proxy_pass push;
        proxy_connect_timeout 15s;
        proxy_timeout 15s;
        proxy_next_upstream_timeout 15s;
     }
    server {
        listen 30851;
        proxy_pass zhongxin;
        proxy_connect_timeout 15s;
        proxy_timeout 15s;
        proxy_next_upstream_timeout 15s;
    }
    server {
        listen 30852;
        proxy_pass zhongxin2;
        proxy_connect_timeout 15s;
        proxy_timeout 15s;
        proxy_next_upstream_timeout 15s;
    }
}

nginx stream模块示例.zip

版权声明:
作者:WaterBear
链接:https://l-t.top/2265.html
来源:雷霆运维
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录