nginx/docker-nginx

best practice to add a stream config?

Closed this issue · 2 comments

udos commented

hi,

I would like to add a stream config similiar to this:

stream {
    server {
      listen 1234;
    
      proxy_connect_timeout 60s;
      proxy_socket_keepalive on;
      proxy_pass localhost:5432;
    }
}

how can I do this?

note: I can not add it to /etc/nginx/conf.d because that is the include directory for http configs...

at the end of nginx.conf, I added:

stream {
include /etc/nginx/streams/*;
}

then, I added that directory:
(From within the container:)
mkdir -p /etc/nginx/streams/

now, just place your server { ... } in a stream.conf inside this very directory.
Do NOT place the stream { ... } in there, as that portion is already inside nginx.conf

Indeed, it's best to provide an edited /etc/nginx/nginx.conf which will include the directory where you'd want to put the stream configuration files to.