├── Dockerfile ├── README.md ├── nginx.conf └── zero_downtime_reload.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:stretch 2 | MAINTAINER Anders Åslund 3 | 4 | RUN apt-get update && apt-get -y upgrade && \ 5 | apt-get install -y wget libpcre3-dev build-essential libssl-dev zlib1g-dev && \ 6 | rm -rf /var/lib/apt/lists/* 7 | 8 | WORKDIR /opt 9 | 10 | RUN wget http://nginx.org/download/nginx-1.23.1.tar.gz && \ 11 | tar -zxvf nginx-1.*.tar.gz && \ 12 | cd nginx-1.* && \ 13 | ./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module --with-ipv6 --with-threads --with-stream --with-stream_ssl_module && \ 14 | make && make install && \ 15 | cd .. && rm -rf nginx-1.* 16 | 17 | # nginx user 18 | RUN adduser --system --no-create-home --disabled-login --disabled-password --group nginx 19 | 20 | # config dirs 21 | RUN mkdir /opt/nginx/http.conf.d && mkdir /opt/nginx/stream.conf.d 22 | 23 | ADD nginx.conf /opt/nginx/conf/nginx.conf 24 | ADD zero_downtime_reload.sh /opt/nginx/sbin/zero_downtime_reload.sh 25 | 26 | WORKDIR / 27 | 28 | EXPOSE 80 443 29 | 30 | CMD ["/opt/nginx/sbin/nginx", "-g", "daemon off;"] 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nginx Stream Dockerfile 2 | Nginx compiled with --with-stream to be able to create proxies or loadbalancers for non http protocols. 3 | 4 | This repository contains **Dockerfile** of Nginx Stream 5 | 6 | ### Base Docker Image 7 | 8 | * [debian](https://hub.docker.com/_/debian/) 9 | 10 | 11 | ### Installation 12 | 13 | 1. Install [Docker](https://www.docker.com/). 14 | 15 | 2. Download: `docker pull tekn0ir/nginx-stream` 16 | 17 | (alternatively, you can build an image from Dockerfile: 18 | ```bash 19 | $ docker build -t="tekn0ir/nginx-stream" github.com/tekn0ir/nginx-stream 20 | ``` 21 | 22 | ### Usage 23 | 24 | Start deamon 25 | ```bash 26 | $ docker run -d -p 0.0.0.0:80:80 --name nginx tekn0ir/nginx-stream 27 | ``` 28 | 29 | ### Configure 30 | Create configuration files in folders example: 31 | ```bash 32 | . 33 | | 34 | |-- http.conf.d 35 | | `-- myhttpservice.conf 36 | | 37 | |-- stream.conf.d 38 | `-- myotherservice.conf 39 | ``` 40 | 41 | myhttpservice.conf example config: 42 | ```conf 43 | upstream myhttpservice { 44 | server srv1.example.com; 45 | server srv2.example.com; 46 | server srv3.example.com; 47 | } 48 | 49 | server { 50 | listen 80; 51 | 52 | location / { 53 | proxy_pass http://myapp1; 54 | } 55 | } 56 | ``` 57 | 58 | myotherservice.conf example config: 59 | ```conf 60 | upstream myotherservice { 61 | server srv1.example.com; 62 | server srv2.example.com; 63 | server srv3.example.com; 64 | } 65 | 66 | server { 67 | listen 65432; 68 | proxy_pass myotherservice; 69 | } 70 | ``` 71 | For little more help on stream config: 72 | https://nginx.org/en/docs/stream/ngx_stream_core_module.html 73 | 74 | Start deamon with configs 75 | ```bash 76 | $ docker run -d -p 80:80 -p 65432:65432 -v `pwd`\http.conf.d:/opt/nginx/http.conf.d -v `pwd`\stream.conf.d:/opt/nginx/stream.conf.d --name nginx tekn0ir/nginx-stream 77 | ``` 78 | 79 | ### Zero downtime reloading of changed configs 80 | If you change settings and need to relaod them on a running container w/o downtime 81 | ```bash 82 | $ docker exec -ti nginx bash -c 'zero_downtime_reload.sh' 83 | ``` -------------------------------------------------------------------------------- /nginx.conf: -------------------------------------------------------------------------------- 1 | 2 | user nginx; 3 | worker_processes auto; 4 | 5 | 6 | events { 7 | worker_connections 1024; 8 | } 9 | 10 | 11 | http { 12 | include mime.types; 13 | default_type application/octet-stream; 14 | 15 | sendfile on; 16 | #tcp_nopush on; 17 | 18 | keepalive_timeout 65; 19 | 20 | #gzip on; 21 | 22 | include /opt/nginx/http.conf.d/*.conf; 23 | } 24 | 25 | stream { 26 | include /opt/nginx/stream.conf.d/*.conf; 27 | } 28 | -------------------------------------------------------------------------------- /zero_downtime_reload.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # HUP is the way to do a graceful reload in nginx 4 | kill -s HUP `cat /opt/nginx/logs/nginx.pid` --------------------------------------------------------------------------------