From e02f17166ab80578d453d5b9c4bb5ae533a92af9 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 3 Nov 2017 19:40:15 +0000 Subject: [PATCH] first commit --- .Dockerfile.swp | Bin 0 -> 12288 bytes .drone.yml | 21 +++ Dockerfile | 104 +++++++++++ README.md | 119 +++++++++++++ auto_upgrade.sh | 32 ++++ docker-compose.yml | 48 ++++++ rootfs/etc/s6.d/.s6-svscan/finish | 3 + rootfs/etc/s6.d/check_certs/run | 7 + rootfs/etc/s6.d/nginx/run | 3 + rootfs/etc/s6.d/tor/run | 3 + rootfs/etc/tor/torrc | 220 ++++++++++++++++++++++++ rootfs/nginx/conf.d/headers.conf | 2 + rootfs/nginx/conf.d/proxy.conf | 9 + rootfs/nginx/conf.d/ssl.conf | 11 ++ rootfs/nginx/conf/nginx.conf | 52 ++++++ rootfs/nginx/path.d/template | 5 + rootfs/nginx/path.d/template_auth | 7 + rootfs/nginx/sites-enabled/template | 6 + rootfs/nginx/sites-enabled/template_ssl | 27 +++ rootfs/nginx/www/letsencrypt | 0 rootfs/usr/local/bin/check_certs | 64 +++++++ rootfs/usr/local/bin/startup | 201 ++++++++++++++++++++++ 22 files changed, 944 insertions(+) create mode 100644 .Dockerfile.swp create mode 100644 .drone.yml create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 auto_upgrade.sh create mode 100644 docker-compose.yml create mode 100644 rootfs/etc/s6.d/.s6-svscan/finish create mode 100644 rootfs/etc/s6.d/check_certs/run create mode 100644 rootfs/etc/s6.d/nginx/run create mode 100644 rootfs/etc/s6.d/tor/run create mode 100644 rootfs/etc/tor/torrc create mode 100644 rootfs/nginx/conf.d/headers.conf create mode 100644 rootfs/nginx/conf.d/proxy.conf create mode 100644 rootfs/nginx/conf.d/ssl.conf create mode 100644 rootfs/nginx/conf/nginx.conf create mode 100644 rootfs/nginx/path.d/template create mode 100644 rootfs/nginx/path.d/template_auth create mode 100644 rootfs/nginx/sites-enabled/template create mode 100644 rootfs/nginx/sites-enabled/template_ssl create mode 100644 rootfs/nginx/www/letsencrypt create mode 100644 rootfs/usr/local/bin/check_certs create mode 100644 rootfs/usr/local/bin/startup diff --git a/.Dockerfile.swp b/.Dockerfile.swp new file mode 100644 index 0000000000000000000000000000000000000000..8c2135d0ac0a930059a09631b58a536296afc764 GIT binary patch literal 12288 zcmeHNO>88^6|M!s#%vZ4$ps0miq2+57OH!G{7W(fdp$Om)?>@N-s}R=sHeN8r|q7u zrn=f5J6dswqG<2YN>NUT1Dp_CK#G)ejvNqL$SEjN1e{QEj3VW${_)J(<6Xl63Dhlr zuI_s8)z9}{y(-Jqsa#uGr8DLv!SgtN>!u&E z>dZ8&S6OwoYVzc6ORFdP+;WAp&86jtP}zQnw@%^*uC&oRon?b=mCM&3dg`(I!7No~A#3V)LZdrC!NE$w0|K$w0|K$w0|K$w0|K z$-wu30TrDhuVWq$$h zUlWA<4R{;41%$u`FbA9iKKUUb?*nfDe*iep0_K2oz-i#C(-<3Y2lyQ@5B&FGLf!$c z0}Pk|{{90({tCPW+yb_MmjD8M`Vhtd>;W$WlRzE#8So!)`fuPf;2*$WfRyL&V4Rdg z{x%u7w7N)NF|3XsTJbcCcVfp5jpwLgapj=KbdBGTX6x$4jrFya)>W;V#L^0cV+Wa$ zvZYEQXp!di^|dQaI$N2o(Amk!I+n?1i#ol&aOtxHI^K{TbYxw$E|N=Y>o=&r4b+XP zMF_=n;R2O?%4C;XsvlVwskLL{QjhKQxMfG%Fv_*?L0ulu^S@o#T)Dj1UTm&kxk+Cw z#QmMDFD0Y}NXLxreiZOSwWI2~KTo9d47eu_Pa&;4XdiNqE9&{Gmvl@=^sNC8MbNbl zsricHMpD=JC}UnAI(9&NN=2sr6+dsG!)V(x{m|@+AP~D7-1Q}QR7{mj_;5OW5DBU1 z^4h{mt8spLZGHagOM0YZG_`(Hte%)Hkg#uS9aKu)NZ`4xQE#e4ss4JVd|1sg9fVoL;?Rg~7Gv#)!`lTy(JC zrAKv4h)i#PI5aQPgm!G@^ibkfm*3qx-p;gR=XmMiR=4?H%q7~SJ==_g2+VjpW(T#g z8N%_5!A(19Ej7+((_da+HinJu>iE!ZhL_VBnL>KFrM4Re!gjN&yNJjqnGW{AZ{M_) z;W!YY)Cok$)4`-MHw;=4@lf(u?O8o;ySN<3`ac~O3WRn}!hB8JG7qK@g+Inq_zLUstx{l2pE|uT)9b55ujA5KG zKH$zc$#hl)oW z_)3M^zIYhhMSP1yF}?WO9VvFPoZDG28>CPxO2**nJk+zadHhN^%I2ZYct28mZO`xK z-HjpmkVT*O)6LC2u|*sOzG^#x&qEcT*vd|n@I#jmPHf?Eabn$MH}?D!Ysb#lQI7B1 zF!Q6GV)Yho)n!ICOXGD5S@1abG1ZgEe&g~*-b5Nnu}V5^Y>_ItFYQ_AdHa5p8u-rr zxXBE5YA4e}ro5M8f_QJ_cb!3kCq)t+e2*gmt8AM^HgbHnEm<-N^F2$8#u69#?lC5i zjJ4oW3dsWD-DQXGtgCh^$BG}9&{#^)J&bKfXWL_~W1N-pZigpYU77Wb@y>57)8Q$m zVK5d+-t`ALCAmhH!qQ|vVu6jnVJuXZCTmmm`b>Rkc4>NPs#;l`tW{@br)rh?xw*Oe zeDzXgs7B&mQIP;<@Sa#u$8?} ze|d0@9Pa6<#h#;L# iv(ppR`P!u-q;?RY5p778Hr7^Y+NYJ(K3_Md$^QZCAkXgr literal 0 HcmV?d00001 diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..cf74e8d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,21 @@ +pipeline: + build: + image: xataz/docker-drone-plugin + repo: xataz/reverse-nginx + action: build + volumes: + - /var/run/docker.sock:/var/run/docker.sock + + push: + image: xataz/docker-drone-plugin + repo: xataz/reverse-nginx + action: push + environment: + - UID=1000 + - GID=991 + volumes: + - /var/run/docker.sock:/var/run/docker.sock + - /home/xataz/.docker/config.json:/docker/.docker/config.json + when: + branch: master + event: [push, tag, deployment] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a959a4f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,104 @@ +FROM xataz/alpine:3.6 + +LABEL Description="reverse with nginx based on alpine" \ + tags="latest mainline 1.13.5 1.13" \ + maintainer="xataz " \ + build_ver="2017090601" + +ARG NGINX_VER=1.13.5 +ARG NGINX_GPG="B0F4253373F8F6F510D42178520A9993A1C052F8" +ARG TOR_GPG="2133BC600AB133E1D826D173FE43009C4607B1FB" +ARG BUILD_CORES +ARG NGINX_CONF="--prefix=/nginx \ + --sbin-path=/usr/local/sbin/nginx \ + --http-log-path=/nginx/log/nginx_access.log \ + --error-log-path=/nginx/log/nginx_error.log \ + --pid-path=/nginx/run/nginx.pid \ + --lock-path=/nginx/run/nginx.lock \ + --user=reverse --group=reverse \ + --with-http_ssl_module \ + --with-http_v2_module \ + --with-http_gzip_static_module \ + --with-http_stub_status_module \ + --with-threads \ + --with-pcre-jit \ + --with-ipv6 \ + --without-http_ssi_module \ + --without-http_scgi_module \ + --without-http_uwsgi_module \ + --without-http_geo_module \ + --without-http_autoindex_module \ + --without-http_split_clients_module \ + --without-http_memcached_module \ + --without-http_empty_gif_module \ + --add-module=/tmp/headers-more-nginx-module \ + --without-http_browser_module" +ARG TOR_VER=0.3.1.7 + +ENV UID=991 \ + GID=991 \ + EMAIL=admin@mydomain.local + +RUN export BUILD_DEPS="build-base \ + libressl-dev \ + pcre-dev \ + zlib-dev \ + libc-dev \ + wget \ + gnupg \ + go \ + libevent-dev \ + git" \ + && NB_CORES=${BUILD_CORES-$(grep -c "processor" /proc/cpuinfo)} \ + && apk add -U ${BUILD_DEPS} \ + s6 \ + su-exec \ + ca-certificates \ + curl \ + jq \ + libressl \ + pcre \ + zlib \ + libevent \ + && cd /tmp \ + && git clone https://github.com/openresty/headers-more-nginx-module --depth=1 \ + && wget http://nginx.org/download/nginx-${NGINX_VER}.tar.gz \ + && wget http://nginx.org/download/nginx-${NGINX_VER}.tar.gz.asc \ + && gpg --keyserver pgp.mit.edu --recv-keys "$NGINX_GPG" || \ + gpg --keyserver keyserver.pgp.com --recv-keys "$NGINX_GPG" || \ + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$NGINX_GPG" \ + && gpg --batch --verify nginx-${NGINX_VER}.tar.gz.asc nginx-${NGINX_VER}.tar.gz \ + && tar xzf nginx-${NGINX_VER}.tar.gz \ + && cd /tmp/nginx-${NGINX_VER} \ + && ./configure ${NGINX_CONF} \ + && make -j ${NB_CORES} \ + && make install \ + && mkdir -p /tmp/go/bin \ + && export GOPATH=/tmp/go \ + && export GOBIN=$GOPATH/bin \ + && git config --global http.https://gopkg.in.followRedirects true \ + && go get github.com/xenolf/lego \ + && mv /tmp/go/bin/lego /usr/local/bin/lego \ + && cd /tmp \ + && wget https://www.torproject.org/dist/tor-${TOR_VER}.tar.gz \ + && wget https://www.torproject.org/dist/tor-${TOR_VER}.tar.gz.asc \ + && gpg --keyserver pgp.mit.edu --recv-keys "$TOR_GPG" || \ + gpg --keyserver keyserver.pgp.com --recv-keys "$TOR_GPG" || \ + gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$TOR_GPG" \ + && gpg --batch --verify tor-${TOR_VER}.tar.gz.asc tor-${TOR_VER}.tar.gz \ + && tar xzf tor-${TOR_VER}.tar.gz \ + && cd tor-${TOR_VER} \ + && ./configure \ + && make -j ${NB_CORES} \ + && make install \ + && mv /usr/local/etc/tor/torrc.sample /usr/local/etc/tor/torrc \ + && apk del ${BUILD_DEPS} \ + && rm -rf /tmp/* /var/cache/apk/* + +COPY rootfs / +RUN chmod +x /usr/local/bin/startup /etc/s6.d/*/* + +EXPOSE 80 443 + +ENTRYPOINT ["/usr/local/bin/startup"] +CMD ["/bin/s6-svscan", "/etc/s6.d"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..ff78ca9 --- /dev/null +++ b/README.md @@ -0,0 +1,119 @@ +![](http://nginx.org/nginx.png) + +# BETA VERSION ACTUALY !!!!! +[![Build Status](https://drone.xataz.net/api/badges/xataz/docker-reverse-nginx/status.svg)](https://drone.xataz.net/xataz/docker-reverse-nginx) +[![](https://images.microbadger.com/badges/image/xataz/reverse-nginx.svg)](https://microbadger.com/images/xataz/reverse-nginx "Get your own image badge on microbadger.com") +[![](https://images.microbadger.com/badges/version/xataz/reverse-nginx.svg)](https://microbadger.com/images/xataz/reverse-nginx "Get your own version badge on microbadger.com") + +> This image is build and push with [drone.io](https://github.com/drone/drone), a circle-ci like self-hosted. +> If you don't trust, you can build yourself. + +## Tag available +* latest, mainline, 1.13.5, 1.13 [(Dockerfile)](https://github.com/xataz/dockerfiles/blob/master/reverse-nginx/Dockerfile) + +## Features +* No ROOT process +* Automatic configuration generation +* Automatic certificate generation and renew with letsencrypt and without downtime (use lego) +* Latest nginx version +* ARG for custom build + +## Description +What is [Nginx](http://nginx.org)? + +nginx (engine x) is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP proxy server, originally written by Igor Sysoev. For a long time, it has been running on many heavily loaded Russian sites including Yandex, Mail.Ru, VK, and Rambler. According to Netcraft, nginx served or proxied 24.29% busiest sites in December 2015. Here are some of the success stories: Netflix, Wordpress.com, FastMail.FM. + +Reverse-nginx generate for you the configuration of reverse proxy. Like traefik, it is based on the labels of containers, but it isn't dynamicly. + +## Build Image +### Build arguments +* NGINX_CONF : Nginx make configure options +* NGINX_VER : Nginx version +* ARG NGINX_GPG : GPG fingerprint (default : "B0F4253373F8F6F510D42178520A9993A1C052F8") +* ARG BUILD_CORES : Number of core use for make nginx (default : All cores) + +### Simply build +```shell +docker build -t xataz/reverse-nginx github.com/xataz/dockerfiles.git#master:reverse-nginx +``` +### Build other version +```shell +docker build -t xataz/reverse-nginx --build-arg NGINX_VER=1.9.5 github.com/xataz/dockerfiles.git#master:reverse-nginx +``` + +## Configuration +### Environments +* UID : Choose uid for launch nginx (default : 991) +* GID : Choose gid for launch nginx (default : 991) + +### Volumes +* /nginx/ssl : For certificate persistance +* /nginx/custom_sites : For create your own sites +* /tor/ : For tor address + +### Ports +* 8080 +* 8443 + +## Usage +### Environments +| Variable | Description | default | value | +| -------- | ----------- | ------- | ----- | +| UID | UID for launch nginx | 991 | Valid UID number | +| GID | GID for launch nginx | 991 | Valid GID number | +| EMAIL | email use for generate letsencrypt certificates | admin@mydomain.local | Valid address mail | + +### Labels +| Label Name | Description | default | value | +| ---------- | ----------- | ------- | ----- | +| reverse.frontend.domain | Domain Name for this service | mydomain.local | valid domain name | +| reverse.frontend.path | Domain path (warning, no rewrite url) | / | valid path, with / | +| reverse.frontend.auth | For auth basic | none | user:encryptpassword | +| reverse.frontend.ssltype | Choose ssl type | ec384 | rsa2048, rsa4096, rsa8192, ec256 or ec384 | +| reverse.frontend.domain\_max\_body\_size | Choose max size upload | 200M | Numeric value with unit (K,M,G,T) | +| reverse.frontend.ssl | Generate letsencrypt certificate | false | true or false | +| reverse.frontend.tor | If container is an hidden service | false | boolean (true / false) | +| reverse.backend.port | Port use by container | 8080 | Valid port number | + + +More labels soon !!! + +### Launch +#### First launch another container +For exemple, I launch lutim container : +```shell +$ docker run -d \ + --name lutim \ + --label reverse.frontend.domain=sub.domain.com \ + --label reverse.frontend.path=lutim \ + --label reverse.frontend.auth=USER:$(openssl passwd -crypt PASSWORD) \ + --label reverse.frontend.ssltype=ec256 \ + --label reverse.frontend.ssl = true \ + --label reverse.backend.port=8181 \ + -v /docker/config/lutim/data:/data \ + -v /docker/data/lutim:/lutim/files \ + -e UID=1001 \ + -e GID=1001 \ + -e WEBROOT=/lutim \ + -e SECRET=$(date +%s | md5sum | head -c 32) \ + -e CONTACT=contact@domain.com \ + -e MAX_FILE_SIZE=250000000 \ + xataz/lutim +``` + + +#### Launch reverse-nginx +```shell +docker run -d \ + -p 80:8080 \ + -p 443:8443 \ + --name reverse \ + -e EMAIL=me@mydomain.com \ + -v /var/run/docker.sock:/var/run/docker.sock \ + xataz/reverse-nginx +``` + +URI Access : https://sub.domain.com/lutim + + + diff --git a/auto_upgrade.sh b/auto_upgrade.sh new file mode 100755 index 0000000..200243e --- /dev/null +++ b/auto_upgrade.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +NGINX_MAINLINE_VERSION=$(grep "NGINX_VER=" Dockerfile | cut -d"=" -f2) +NEW_NGINX_MAINLINE_VERSION=$(curl http://nginx.org/en/download.html 2> /dev/null | sed 's|>|>\n|g' | grep '^