Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to enable stream module in nginx container

I want to proxy mongodb behind nginx. And I came across following code for same purpose.

My question is, how can I enable "stream" module in nginx?

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

    upstream mongodb_host{
        server xx.xxx.xxx.xx:27017;
    }
}
like image 992
Amrit jeet Avatar asked Nov 21 '25 01:11

Amrit jeet


1 Answers

Technically recompiling using the --with-stream option is required, as per the nginx docs. Fortunately there are plenty of existing images for that purpose. I've used this one personally: https://hub.docker.com/r/tekn0ir/nginx-stream

If using compose, your docker-compose.yml file would look something like this -

version: '3'  
services:  
    service1:  
        ...  
    service2:  
        ...  
    nginx:  
        image: tekn0ir/nginx-stream:latest  
        ports:   
            - "27020:27020"   
        volumes:   
            - /usr/local/nginx/conf/http:/opt/nginx/http.conf.d
            - /usr/local/nginx/conf/stream:/opt/nginx/stream.conf.d

Create 1 or more files in the "/usr/local/nginx/conf/stream" directory containing your code stream { ... } . Config file names just need to end with the ".conf" extension. Then you can create any http config files in "/usr/local/nginx/conf/http".

like image 187
jrbe228 Avatar answered Nov 23 '25 22:11

jrbe228