Nginx转发MySQL端口及添加stream模块

1.在nginx.conf的http同级添加stream配置

stream {

upstream mysql_server{

server 192.168.23.25:3306;

}

server {

listen 8560;

proxy_pass mysql_server;

}

}

http {

....

}

启动nginx后发现报错如下,找不到stream模块,该模块在nginx1.9版本后才支持的:
nginx: [emerg] unknown directive "stream" in /usr/local/nginx//conf/nginx``.conf:118

2.查看nginx编译模块

portal@host02/lvdata/portal/install/nginx/sbin$ ./nginx -V

nginx version: nginx/1.26.0

built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)

built with OpenSSL 1.0.2k-fips 26 Jan 2017

TLS SNI support enabled

configure arguments: --prefix=../nginx --with-http_ssl_module

3.重新编译nginx

3.1下载相同版本的nginx并解压

portal@host02/lvdata/portal$ tar -xvf nginx-1.26.0.tar.gz

3.2重新编译

重新编译,指定--prefix的路径,即nginx安装路径,后面nginx生成的logs等都在此目录下面,只执行make即可,请不要执行后面的install命令,编译后切换到objs目录,即可看到重新生成的nginx文件,备份好的原来的nginx,拷贝新生成的覆盖原来的重启即可。

portal@host02/lvdata/portal/nginx-1.26.0$ ./configure --prefix=/lvdata/portal/install/nginx --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream

portal@host02/lvdata/portal/nginx-1.26.0$ make

portal@host02/lvdata/portal/nginx-1.26.0$cd objs

portal@host02/lvdata/portal/nginx-1.26.0/objs$ ll

total 7880

-rw-rw-r-- 1 portal portal 22613 Nov 2 11:09 autoconf.err

-rw-rw-r-- 1 portal portal 53112 Nov 2 11:09 Makefile

-rwxrwxr-x 1 portal portal 7861920 Nov 2 11:10 nginx

-rw-rw-r-- 1 portal portal 5585 Nov 2 11:10 nginx.8

-rw-rw-r-- 1 portal portal 7595 Nov 2 11:09 ngx_auto_config.h

-rw-rw-r-- 1 portal portal 657 Nov 2 11:09 ngx_auto_headers.h

-rw-rw-r-- 1 portal portal 8654 Nov 2 11:09 ngx_modules.c

-rw-rw-r-- 1 portal portal 92688 Nov 2 11:10 ngx_modules.o

drwxrwxr-x 9 portal portal 91 Nov 2 11:09 src

portal@host02/lvdata/portal/nginx-1.26.0/objs$ cp nginx /lvdata/portal/install/nginx/sbin

注意: 如果prefix路径指定得不对,启动提示报错如下:

portal@host02/lvdata/portal/install/nginx/sbin$ ./nginx -s reload

nginx: alert could not open error log file: open() "/lvdata/portal/nginx-1.26.0/logs/error.log" failed (2: No such file or directory)

2024/11/02 11:00:13 notice 16812#0: signal process started

2024/11/02 11:00:13 error 16812#0: open() "/lvdata/portal/nginx-1.26.0/logs/nginx.pid" failed (2: No such file or directory)

3.3重启Nginx

portal@host02/lvdata/portal/install/nginx/sbin$ cd /lvdata/portal/install/nginx/sbin

portal@host02/lvdata/portal/install/nginx/sbin$./nginx -s reload

相关推荐
智能运维指南5 小时前
代码管理软件如何融入 DevOps 工具链?全链路联通的 5 个关键点
运维·devops·信创适配·嘉为蓝鲸
充电zcx5 小时前
Linux:4:开发工具详解
linux·运维·服务器
gongfeng30009 小时前
福州企业级AI自动化获客解决方案品牌梳理与适用场景分析
运维·人工智能·自动化·g-claw ai员工
光电笑映10 小时前
网络通信基础:从协议分层到 Socket 编程预备
linux·运维·服务器·网络
微小冷11 小时前
用Mermaid画时序图
运维·流程图·时序图·mermaid·生命线
其实防守也摸鱼11 小时前
Codex 下载与本地部署实战:从安装到运行全指南
android·大数据·运维·安全·自动化
wdfk_prog11 小时前
ROS教程07:从 ros::start() 顺着源码读懂 Master、XML-RPC 与 Topic 注册发现
运维·缓存·docker·容器·ros
吴声子夜歌12 小时前
Shell编程实例——与解析相关的任务(二)
linux·运维·shell
倔强的石头10613 小时前
【Linux指南】动静态库系列(八):ELF 加载与进程地址空间:程序还没运行,为什么已经有地址
linux·运维
两点王爷13 小时前
常用的 Docker 镜像拉取地址仓库及常用命令详解
运维·服务器·容器