• 解决nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf问题



    1.未报错时nginx配置:

    #user  nginx;
    user  root;
    worker_processes  auto;
    
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
       # access_log  /var/log/nginx/access.log  main;
      client_max_body_size 30m;
      client_body_buffer_size 10m;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    	upstream wms-admin-web {
            server 192.168.0.2:8082 max_fails=2 fail_timeout=10s;
            server 192.168.0.3:8082 max_fails=2 fail_timeout=10s;
            server 192.168.0.203:8082 max_fails=2 fail_timeout=10s;
            #server 192.168.0.221:8082 max_fails=2 fail_timeout=10s;
           }
    
     upstream wms {
            server 192.168.0.2:8083 max_fails=2 fail_timeout=10s;
            #server 192.168.0.221:8083 max_fails=2 fail_timeout=10s;
           }
    	   
    	 upstream nacos_server {
    	  server 192.168.0.2:8848  weight=1 max_fails=1 fail_timeout=10s;
    	  server 192.168.0.3:8848  weight=1 max_fails=1 fail_timeout=10s;
    	  server 192.168.0.203:8848  weight=1 max_fails=1 fail_timeout=10s;
    	}
    
      server {
           listen       80;
          server_name  localhost;
    
          rewrite_log on;
          error_log    /var/log/nginx/error.log notice;
    
         location / {
             root   /home/nginx/html;
             #root   /usr/share/nginx/html;
             index index.html /home/nginx/index.html;
    	#	proxy_pass http://wms-admin-web;
            } 
      }
    
     server {
            listen       8090;
            server_name  localhost;
    
            rewrite_log on;
            error_log      /var/log/nginx/error.log notice;
    	
    	location /download/ {
               root /home/nginx/;
            }
    
            location /img/ {
               root /home/nginx/;
            }
    
            location / {
                proxy_pass http://wms;
                proxy_set_header Host $host:$server_port;
            } 
       }
    
    	# nacos-server配置
    	server {
    		listen 8858;
    		server_name nacos.com; #nacos.com 映射配置
    		location / {
    			proxy_pass http://nacos_server;
    			proxy_set_header Host $host;
    			proxy_set_header X-Real-IP $remote_addr;
    			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    			proxy_set_header REMOTE-HOST $remote_addr;
    			add_header X-Cache $upstream_cache_status;
    			add_header Cache-Control no-cache;
    		}
    	}
    
        include /etc/nginx/conf.d/*.conf;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103

    2.报错时nginx配置:

    load_module /usr/lib64/nginx/modules/ngx_stream_module.so;
    #user  nginx;
    user  root;
    worker_processes  auto;
    
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    #redis代理测试
    stream {
         upstream redis {
            #redis真实访问地址
            server  192.168.0.2:6701 max_fails=3 fail_timeout=30s;
         }
     
         server {
              #外网监听地址
              listen 6379;
              #代理连接超时时间
              proxy_connect_timeout 5s;
              #代理超时时间
              proxy_timeout 30s;
              #代理名称
              proxy_pass redis;
         }
    }
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
       # access_log  /var/log/nginx/access.log  main;
      client_max_body_size 30m;
    client_body_buffer_size 10m;
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
    	upstream wms-admin-web {
            server 192.168.0.2:8082 max_fails=2 fail_timeout=10s;
            server 192.168.0.3:8082 max_fails=2 fail_timeout=10s;
            server 192.168.0.203:8082 max_fails=2 fail_timeout=10s;
            #server 192.168.0.221:8082 max_fails=2 fail_timeout=10s;
           }
    
     upstream wms {
            server 192.168.0.2:8083 max_fails=2 fail_timeout=10s;
            #server 192.168.0.221:8083 max_fails=2 fail_timeout=10s;
           }
    	   
    	 upstream nacos_server {
    	  server 192.168.0.2:8848  weight=1 max_fails=1 fail_timeout=10s;
    	  server 192.168.0.3:8848  weight=1 max_fails=1 fail_timeout=10s;
    	  server 192.168.0.203:8848  weight=1 max_fails=1 fail_timeout=10s;
    	}
    
      server {
           listen       80;
          server_name  localhost;
    
          rewrite_log on;
          error_log    /var/log/nginx/error.log notice;
    
         location / {
             root   /home/nginx/html;
             #root   /usr/share/nginx/html;
             index index.html /home/nginx/index.html;
    	#	proxy_pass http://wms-admin-web;
            } 
      }
    
     server {
            listen       8090;
            server_name  localhost;
    
            rewrite_log on;
            error_log      /var/log/nginx/error.log notice;
    	
    	location /download/ {
               root /home/nginx/;
            }
    
            location /img/ {
               root /home/nginx/;
            }
    
            location / {
                proxy_pass http://wms;
                proxy_set_header Host $host:$server_port;
            } 
       }
    
    	# nacos-server配置
    	server {
    		listen 8858;
    		server_name nacos.com; #nacos.com 映射配置
    		location / {
    			proxy_pass http://nacos_server;
    			proxy_set_header Host $host;
    			proxy_set_header X-Real-IP $remote_addr;
    			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    			proxy_set_header REMOTE-HOST $remote_addr;
    			add_header X-Cache $upstream_cache_status;
    			add_header Cache-Control no-cache;
    		}
    	}
    
        include /etc/nginx/conf.d/*.conf;
    
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124

    3.增加配置报错:

    增加配置内容如下:

    #redis代理测试
    stream {
         upstream redis {
            #redis真实访问地址
            server  192.168.0.2:6701 max_fails=3 fail_timeout=30s;
         }
     
         server {
              #外网监听地址
              listen 6379;
              #代理连接超时时间
              proxy_connect_timeout 5s;
              #代理超时时间
              proxy_timeout 30s;
              #代理名称
              proxy_pass redis;
         }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    4.增加配置位置如下:

    在这里插入图片描述

    5.解决办法:

    1.nginx -V确保nginx安装了–with -stream如果没有,重新用yum install nginx -y安装
    2. 安装 yum -y install epel-release
    3. yum -y install nginx-all-modules.noarch
    4.vi nginx.conf顶部加一行
    load_module /usr/lib64/nginx/modules/ngx_stream_module.so;

    6.测试:nginx -t

  • 相关阅读:
    4路光栅尺磁栅尺编码器解码转换5MHz高速差分信号转Modbus TCP网络模块 YL97-RJ45
    【老生谈算法】matlab实现聚类分析源码——聚类分析
    MybatisPlus搭建项目
    javaWeb监听器Listener -自定义监听器类实现(二)
    C++:优先级队列模拟实现和仿函数的概念使用
    决策树可视化方法与技巧汇总(1)(分类决策树)(含Python代码示例)
    非零基础自学Java (老师:韩顺平) 第6章 数组、排序和查找 6.4 数组应用案例 && 6.5 数组赋值机制 && 6.6 数组拷贝
    海外跨境商城电商源码-进出口电商平台网站-多语言多商户多货币平台
    C语言幂级数求近似值
    [Vue3 博物馆管理系统] 使用Vue3、Element-plus的Layout 布局构建组图文章
  • 原文地址:https://blog.csdn.net/User_bie/article/details/128102168