Nginx – Setting up mongodb behind nginx

mongodbnginx

I am trying to setup mongodb behind nginx, and below is the configuration I used. But I keep getting the following error when I reload nginx. Any help is appreciated.

nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/sites-enabled/mongodb:1

stream {
    server {
        listen 27020;
        proxy_connect_timeout 5s;
        proxy_timeout 20s;
        proxy_pass    stream_mongo_backend;
    }

    upstream stream_mongo_backend {
        server 127.0.0.1:27017;
    }  
}

Best Answer

Check nginx.conf where the sites-enabled files are included.

Thats probably done in the http section of the conf file, but the stream directive is only allowed in the main section as stated here: http://nginx.org/en/docs/stream/ngx_stream_core_module.html#stream

You have to move your directive in nginx.conf file itself:

user ...
...
http {
  ...
}
stream {
  ...
}
Related Topic