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

这篇具有很好参考价值的文章主要介绍了解决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;
}

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;

}


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;
     }
}

4.增加配置位置如下:

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

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;文章来源地址https://www.toymoban.com/news/detail-402943.html

6.测试:nginx -t

到了这里,关于解决nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包