nginx1.16.1长连接

安装nginx1.16.1

yum install gcc-c++ pcre* openssl* -y
mkdir /opt
cd /opt
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxvf nginx-1.16.1.tar.gz 
cd nginx-1.16.1
./configure --prefix=/opt/nginx --with-http_ssl_module --with-stream
make&&make install

多实例nginx启动需指定配置文件
/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

编辑nginx socket长连接
vim /opt/nginx/conf/nginx.conf

upstream shuiwu {
        keepalive 300;
        server 2.16.124.223:81;
}

server {

    location / {
        proxy_pass http://shuiwu/;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_read_timeout 600s
        proxy_pass_header Server;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;

    }
}

nginx自1.9.0开始提供tcp/udp的反向代理功能,直到1.11.4才开始提供session日志功能。启用stream日志配置文件
主配置文件/etc/nginx/nginx.conf增加内容:

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 /opt/nginx/logs/tcp-access.log proxy ;
    open_log_file_cache off;
    include /etc/nginx/conf.d/*.stream;
}


upstream TCP59001 {
        hash $remote_addr consistent;
        server 192.168.1.176:59001;
    }
        server {
        listen 59001;
        proxy_connect_timeout 5s;
        proxy_timeout 30s;
        proxy_pass TCP59001;
    }

/opt/nginx/sbin/nginx -t
/opt/nginx/sbin/nginx

日志目录
tailf /opt/nginx/logs/tcp-access.log

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值