moneyslow.com

nginx报错"stream"/"upstream" directive is not allowed 错误

nginx

nginx

这个错误,你一定要看清楚是steam还是upstream?一个和http段平行,一个在http段里。
在nginx 1.10版本里,叫steam
在nginx 1.14版本里,叫upsteam

所以,如果你用的是nginx的1.10版本的steam,那么http段和steam段是平行的,大概配置如下:

http {
。。。。。
}
stream {
    upstream tongji {
        hash $remote_addr consistent;
        server 109.10.8.12:80 weight=5 max_fails=1 fail_timeout=10s;
    }

    server {
        listen 80;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass tongji;
    }
}

如果你用的是nginx的1.14的upstream,那么upsteam段是在http段里的,大概配置如下:

http {

....

upstream moneyslow {
        server 109.10.8.12:80;
    }
 
    server {
        listen       80;
        server_name  moneyslow.com;
 
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
 
        location / {
            proxy_pass   http://moneyslow;
            index  index.html index.htm;
        }        
    }
    
}
Exit mobile version