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