From 642b111340a25a7ef6895aa05e2ecb636b67d6d4 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Sat, 22 Aug 2020 22:59:07 +0200 Subject: [PATCH] Moving on git --- .env.example | 9 +++++++++ .gitignore | 1 + Dockerfile | 10 ++++++++++ docker-compose.yml | 19 +++++++++++++++++++ root/defaults/nginx.conf | 34 ++++++++++++++++++++++++++++++++++ root/entrypoint.sh | 25 +++++++++++++++++++++++++ static-websites.env.example | 5 +++++ 7 files changed, 103 insertions(+) create mode 100644 .env.example create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 root/defaults/nginx.conf create mode 100755 root/entrypoint.sh create mode 100644 static-websites.env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..44b6c28 --- /dev/null +++ b/.env.example @@ -0,0 +1,9 @@ +# Global Settings +LOCAL_STACK_DIR=/srv/docker/volumes/static-websites + +# Networks +NETWORK=webservices + +# static-websites +NG_CONTAINER_NAME= +NG_RESTART= diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..03bd412 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6f8f859 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM nginx:stable-alpine + +LABEL maintainer="Meliurwen " + +RUN apk --no-cache add tzdata && \ + mkdir -p /defaults /data /config/conf.d + +COPY root/ / + +ENTRYPOINT [entrypoint.sh] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..5cf1d69 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +version: "3" + +services: + static-websites: + build: . + container_name: ${NG_CONTAINER_NAME:-nginx-static-websites} + restart: ${NG_RESTART:-unless-stopped} + volumes: + - ${LOCAL_STACK_DIR}/data:/data:ro + - ${LOCAL_STACK_DIR}/config:/config:ro + env_file: + - static-websites.env + environment: + - TZ=${TZ} + +networks: + default: + external: + name: ${NETWORK} diff --git a/root/defaults/nginx.conf b/root/defaults/nginx.conf new file mode 100644 index 0000000..44bc59e --- /dev/null +++ b/root/defaults/nginx.conf @@ -0,0 +1,34 @@ +user nginx; +worker_processes 4; +#include /etc/nginx/modules/*.conf; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 512; +} + +http { + include /config/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + + keepalive_timeout 65; + + gzip on; + gzip_disable "msie6"; + + include /config/conf.d/*.conf; +} + +daemon off; diff --git a/root/entrypoint.sh b/root/entrypoint.sh new file mode 100755 index 0000000..01989ce --- /dev/null +++ b/root/entrypoint.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# Exit at first error +set -e + +# Check if nginx configuration file exists +if [ ! -e /config/nginx.conf ]; then + echo "Configuration file nginx.conf not found. Initializing..."; + cp /defaults/nginx.conf /config/nginx.conf; +fi + +# Check if nginx configuration file exists +if [ ! -e /config/mime.types ]; then + echo "Configuration file mime.types not found. Initializing..."; + cp /etc/nginx/mime.types /config/mime.types; +fi + +# Check if conf.d directory has websites configuration files +if [ -z "$(ls -A /config/conf.d)" ]; then + echo "The /config/conf.d directory is empty. Copying default.conf..."; + cp /etc/nginx/conf.d/default.conf /config/conf.d/default.conf; +fi + +# Launch nginx +nginx -c /config/nginx.conf diff --git a/static-websites.env.example b/static-websites.env.example new file mode 100644 index 0000000..bc8ba3e --- /dev/null +++ b/static-websites.env.example @@ -0,0 +1,5 @@ +# Reverse-proxy and certbot +VIRTUAL_HOST=subdomain.domain.tld +VIRTUAL_PORT=80 +LETSENCRYPT_HOST=subdomain.domain.tld +LETSENCRYPT_EMAIL=username@domain.tld