小工具知识网

当前位置: 首页 > 行业知识 > 解决nginx: [emerg] unknown directive “stream“ in /etc/nginx/nginx.conf问题

行业知识

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

2026-11-16 00:58:57 来源:互联网转载

文章目录

    • 1.未报错时nginx配置:
    • 2.报错时nginx配置:
    • 3.增加配置报错:
    • 4.增加配置位置如下:
    • 5.解决办法:
    • 6.���试:nginx -t

      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.增加配置位置如下:

      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

上一篇:Java论坛源码深度解析,探索BBS系统的核心架构与功能实战揭秘

下一篇:如何利用迅雷下载百度网盘文件