Web负载均衡学习笔记之nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf

2022-09-27 19:13:14 浏览数 (1)

0x00 概述

yum安装nginx后,启动nginx报错,报错信息如下:

代码语言:javascript复制
nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf

nginx配置文件如下,配合keepalived使用:

代码语言:javascript复制
[root@k8s-node2 ~]# cat /etc/nginx/nginx.conf
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;
    }
}

0x01 解决方法

代码语言:javascript复制
# 安装nginx源
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 先安装
yum -y install epel-release

#应该是缺少modules模块
yum -y install nginx-all-modules.noarch
然后在用nginx -t就好了
[root@k8s-node2 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

0 人点赞