From 46fc3d4a2e406902699c52f27009cf61f2809dc8 Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sat, 10 Aug 2019 22:46:44 +0200 Subject: [PATCH] initial commit --- Dockerfile | 38 +++++++++++++++++++++++++++++++++++ README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++ conf/default.conf | 17 ++++++++++++++++ conf/nginx.conf | 47 ++++++++++++++++++++++++++++++++++++++++++++ html/error.html | 18 +++++++++++++++++ 5 files changed, 170 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 conf/default.conf create mode 100644 conf/nginx.conf create mode 100644 html/error.html diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..861a674 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +FROM alpine AS builder + +ARG DEP_DEV="alpine-sdk zlib-dev pcre-dev openssl-dev gd-dev" +ARG NGINX_MODULES="--with-http_realip_module --with-threads --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_secure_link_module" +ARG NGINX=1.16.0 + +RUN apk add --no-cache ${DEP_DEV} + +WORKDIR /build + +RUN curl https://nginx.org/download/nginx-${NGINX}.tar.gz | tar xz +RUN mv nginx-${NGINX} nginx +RUN git clone --recursive https://github.com/google/ngx_brotli.git + +WORKDIR /build/nginx +RUN ./configure ${NGINX_MODULES} --add-module=../ngx_brotli +RUN make && make install + + + +FROM alpine + +ARG DEP_RUN="pcre openssl gd tzdata" + +COPY --from=builder /usr/local/nginx /usr/local/nginx +RUN apk add --no-cache ${DEP_RUN} \ + && ln -sf /dev/stdout /usr/local/nginx/logs/access.log \ + && ln -sf /dev/stderr /usr/local/nginx/logs/error.log + +COPY ./conf/nginx.conf /usr/local/nginx/conf/nginx.conf +COPY ./conf/default.conf /usr/local/nginx/conf/sites/default.conf +COPY ./html/error.html /usr/local/nginx/html/error.html + +EXPOSE 80 + +STOPSIGNAL SIGTERM + +CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc5acb6 --- /dev/null +++ b/README.md @@ -0,0 +1,50 @@ +# NGINX Static Server + +This is a little docker image for histing static content efficiently. +Supports ETags & Brotli/GZip compression out of the box. + +## Quickstart 🚀 + +```yaml +# docker-compose.yml +version: '3.7' + +services: + server: + image: cupcakearmy/static + restart: unless-stopped + ports: + - 80:80 + volumes: + - ./public:/srv:ro +``` + +```bash +docker-compose up -d +``` + +### Custom Configuration + +``` +# my.conf +server { + listen 80; + server_name _; + + location / { + root /srv; + try_files $uri /index.html =404; + } +} +``` + +```yaml +version: '3.7' + +services: + server: + # ... + volumes: + - ./my.conf:/usr/local/nginx/conf/sites/default.conf + # ... +``` diff --git a/conf/default.conf b/conf/default.conf new file mode 100644 index 0000000..c8b9952 --- /dev/null +++ b/conf/default.conf @@ -0,0 +1,17 @@ +server { + listen 80; + server_name _; + + location / { + root /srv; + try_files $uri /index.html =404; + } + + error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /error.html; + error_page 500 501 502 503 504 505 506 507 508 509 510 511 /error.html; + location = /error.html { + internal; + root /usr/local/nginx/html; + } + +} \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf new file mode 100644 index 0000000..fec48ac --- /dev/null +++ b/conf/nginx.conf @@ -0,0 +1,47 @@ +user nobody; +worker_processes auto; + + +events { + worker_connections 1024; +} + + +http { + include mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_x_forwarded_for"'; + + sendfile on; + keepalive_timeout 30; + + etag on; + gzip on; + brotli on; + brotli_types *; + + server_tokens off; + + include sites/*.conf; + + # server { + # listen 80; + # server_name _; + + # location / { + # root /srv; + # try_files $uri /index.html =404; + + # # add_header Cache-Control "public, max-age=86400, stale-while-revalidate=604800, stale-if-error=604800"; + # } + + # error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /error.html; + # error_page 500 501 502 503 504 505 506 507 508 509 510 511 /error.html; + # location = /error.html { + # internal; + # root /usr/local/nginx/html; + # } + + # } +} \ No newline at end of file diff --git a/html/error.html b/html/error.html new file mode 100644 index 0000000..2ab69c7 --- /dev/null +++ b/html/error.html @@ -0,0 +1,18 @@ + + + + + + +

error

+ + \ No newline at end of file