nginx stream无法使用的解决办法 第1张

目录

错误代码
[root@xxx nginx]# ./sbin/nginx -t
nginx: [emerg] unknown directive "stream" in /usr/local/nginx//conf/nginx.conf:118
nginx: configuration file /usr/local/nginx//conf/nginx.conf test failed

#或者这种
[root@xxx nginx]# ./sbin/nginx -t
nginx: [emerg] dlopen() "/usr/lib64/nginx/modules/ngx_stream_module.so" failed (/usr/lib64/nginx/modules/ngx_stream_module.so: undefined symbol: ngx_ssl_session_cache_init) in /usr/local/nginx/conf/nginx.conf:2
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

解决办法
  • 先删除原有的nginx
  • 重新构建nginx
# 添加使用--with-stream=dynamic 配置
./configure --prefix=/usr/local/nginx/ --with-stream=dynamic
# 然后make  make install
make
make install
  • 到/usr/local/nginx/ 中发现多了modules文件夹
[root@fhd nginx]# ll
total 0
drwxr-xr-x 2 root root 333 Mar  9 11:10 conf
drwxr-xr-x 2 root root  40 Mar  9 11:09 html
drwxr-xr-x 2 root root   6 Mar  9 11:09 logs
drwxr-xr-x 2 root root  34 Mar  9 11:09 modules
drwxr-xr-x 2 root root  19 Mar  9 11:09 sbin
  • 修改nginx.conf文件, 在首行添加 load_module /usr/local/nginx/modules/ngx_stream_module.so;
load_module /usr/local/nginx/modules/ngx_stream_module.so;
  • 再次使用stream
stream {
	upstream kube-apiserver {
	server 192.168.10.64:6443     max_fails=3 fail_timeout=30s;
	server 192.168.10.65:6443     max_fails=3 fail_timeout=30s;
}
 server {
	 listen 7443;
	 proxy_connect_timeout 2s;
	 proxy_timeout 900s;
	 proxy_pass kube-apiserver;
	}
}
[root@fhd nginx]# ./sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
  • 此时发现测试配置文件通过, 可以成功启动nginx

到此这篇关于nginx stream无法使用的解决办法的文章就介绍到这了,更多相关nginx stream无法使用内容请搜索考高分网以前的文章或继续浏览下面的相关文章希望大家以后多多支持考高分网!

收藏(0)