内网nginx安装stream模块,配置nginx转发mysql端口

该文章详细介绍了如何在Linux环境中检查已安装的nginx模块,发现缺少stream模块后,如何重新编译安装nginx以包含stream和stream_ssl_module。接着,通过配置stream模块,设置端口转发,将本地8080端口的流量转发到远程MySQL服务器的3306端口,提供了两种不同的配置方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内网安装stream模块 

1.先进到原来nginx的sbin目录,查看原来安装的配置模块
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.19.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.1.1g  21 Apr 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
2.原来安装的模块没有stream模块,然后进入原来安装nginx解压包的目录里面
[root@localhost ~]# find / -name nginx
/root/soft/nginx-1.19.5/objs/nginx
/var/spool/mail/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
/home/nginx

我原来的目录是在/root/soft/nginx-1.19.5/下面
[root@localhost ~]# cd /root/soft/nginx-1.19.5
[root@localhost nginx-1.19.5]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@localhost nginx-1.19.5]# ./configure --prefix=/usr/local/nginx --with-stream --with-stream_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

...
等待编译完成


[root@localhost nginx-1.19.5]# make    #注意不要 make install ! ! !

...
等待make完成


3.然后进入到/root/soft/nginx-1.19.5/objs目录下面将nginx拷贝到现在nginx的目录/usr/local/nginx/sbin/ 下面,注意先备份原来/usr/local/nginx/sbin/下的nginx
[root@localhost nginx-1.19.5]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.back
[root@localhost nginx-1.19.5]# cd objs/
[root@localhost objs]# ls
autoconf.err  Makefile  nginx  nginx.8  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  ngx_modules.o  src
[root@oss-rwrk-22 objs]# cp -ar nginx /usr/local/nginx/sbin/

4.先停掉原来的nginx然后用新的nginx启动
[root@localhost objs]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ls
[root@localhost sbin]# nginx  nginx.back
[root@localhost sbin]# ./nginx 



配置stream模块转发mysql端口

vim nginx.conf
#user  nobody;
worker_processes  1;

events {
    worker_connections  1024;
}

#这里配置nginx转发mysql端口
stream {
    #方法一:
    upstream mysql_3306 {
       hash $remote_addr consistent;
       server 10.10.10.10:3306 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 8080;  #配置本机的监听端口,访问本机的8080端口跳转到10.10.10.10:3306端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s;   #设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
       proxy_pass mysql_3306;
    }

    #方法二:
    server {
       listen 8088;
       proxy_pass 10.10.10.11:3306;
    }
}

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

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小邋遢2.0

你的鼓励将是我创作的最大动力~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值