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

相关推荐
qq_452396232 小时前
第十五篇:《UI自动化中的稳定性优化:解决flaky tests的七种武器》
运维·ui·自动化
j_xxx404_2 小时前
Linux:静态链接与动态链接深度解析
linux·运维·服务器·c++·人工智能
Elastic 中国社区官方博客3 小时前
Elastic-caveman : 在不损失 Elastic 最佳效果的情况下,将 AI 响应 tokens 减少64%
大数据·运维·数据库·人工智能·elasticsearch·搜索引擎·全文检索
jsons14 小时前
给每台虚拟机设置独立控制台密码
linux·运维·服务器
云栖梦泽5 小时前
Linux内核与驱动:14.SPI子系统
linux·运维·服务器·c++
福大大架构师每日一题6 小时前
openclaw v2026.4.24 发布:Google Meet 深度集成、DeepSeek V4 上线、浏览器自动化与插件架构全面升级
运维·架构·自动化·openclaw
yipiantian6 小时前
在Claude项目中实现跨目录访问Skills
linux·运维·服务器
Agent产品评测局6 小时前
生产排期与MES/ERP系统打通,实操方法详解 —— 2026企业级智能体自动化选型与实战指南
java·运维·人工智能·ai·chatgpt·自动化
cen__y6 小时前
Linux07(信号01)
linux·运维·服务器·c语言·开发语言
MT5开发6 小时前
Linux安装MariaDB
linux·运维·mariadb