nginx通过stream模块实现反向代理

下载nginx包,具体版本查看Nginx官方下载地址

wget http://nginx.org/download/nginx-1.17.10.tar.gz

一些编译安装要用到的依赖包

yum -y install gcc  gcc-c++  make pcre-devel zlib-devel openssl-devel

openssl-devel(用于加密)

nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等

默认安装的nginx是没有开启stream模块的,需要在安装时添加,如果已经安装了,后续安装的话,请看这篇文章NGINX的后续模块添加

在nginx的解压包里执行,已添加了stream模块

./configure --prefix=/usr/local/nginx \--with-http_stub_status_module \--with-http_ssl_module \--with-http_realip_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gzip_static_module \--with-stream \--with-stream_ssl_module && make  && make install

然后修改配置文件

vi /usr/local/nginx/conf/nginx.conf
#已省略无关部分
events {
    worker_connections  1024;
}
#如有需要可添加多个server
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 logs/tcp-access.log proxy;

server{
       listen 12345 so_keepalive=on; #监听本机12345端口
       proxy_pass 172.14.15.16:12345; #转发到该ip的12345端口
       }
}

http {
    include       mime.types;
    default_type  application/octet-stream;

原文链接: https://www.cnblogs.com/yuan9910/p/13999057.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/205157

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月12日 下午10:08
下一篇 2023年2月12日 下午10:08

相关推荐