commit 642b111340a25a7ef6895aa05e2ecb636b67d6d4 Author: meliurwen Date: Sat Aug 22 22:59:07 2020 +0200 Moving on git 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