From b9950596bb000d3a6705d19d835b7e21037f0da3 Mon Sep 17 00:00:00 2001 From: Raine Date: Fri, 20 Oct 2023 02:09:03 +0200 Subject: [PATCH] feat: default nginx config --- .../docker-compose.d/custom/nginx/Dockerfile | 12 +++++++ .../custom/nginx/conf.d/default.conf | 24 ++++++++++++++ .../custom/nginx/content/index.html | 24 ++++++++++++++ .../custom/nginx/entrypoint.sh | 22 +++++++++++++ .../docker-compose.d/custom/nginx/nginx.conf | 32 +++++++++++++++++++ .../skel/docker-compose.d/docker-compose.yml | 23 +++++++++++++ 6 files changed, 137 insertions(+) create mode 100644 servers/skel/docker-compose.d/custom/nginx/Dockerfile create mode 100644 servers/skel/docker-compose.d/custom/nginx/conf.d/default.conf create mode 100644 servers/skel/docker-compose.d/custom/nginx/content/index.html create mode 100644 servers/skel/docker-compose.d/custom/nginx/entrypoint.sh create mode 100644 servers/skel/docker-compose.d/custom/nginx/nginx.conf create mode 100644 servers/skel/docker-compose.d/docker-compose.yml diff --git a/servers/skel/docker-compose.d/custom/nginx/Dockerfile b/servers/skel/docker-compose.d/custom/nginx/Dockerfile new file mode 100644 index 0000000..4e819e7 --- /dev/null +++ b/servers/skel/docker-compose.d/custom/nginx/Dockerfile @@ -0,0 +1,12 @@ +FROM nginx:alpine + +RUN apk add \ + certbot \ + certbot-nginx + +COPY content /usr/share/nginx/html +COPY conf.d /etc/nginx +COPY nginx.conf /etc/nginx/nginx.conf + +COPY entrypoint.sh /entrypoint +ENTRYPOINT [ "sh", "/entrypoint" ] \ No newline at end of file diff --git a/servers/skel/docker-compose.d/custom/nginx/conf.d/default.conf b/servers/skel/docker-compose.d/custom/nginx/conf.d/default.conf new file mode 100644 index 0000000..e58e934 --- /dev/null +++ b/servers/skel/docker-compose.d/custom/nginx/conf.d/default.conf @@ -0,0 +1,24 @@ +server { + listen 80; + server_name localhost; + + # default html page + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} + +server { + listen 443 ssl; + server_name localhost; + + location / { + proxy_pass http://$host$request_uri; + } +} \ No newline at end of file diff --git a/servers/skel/docker-compose.d/custom/nginx/content/index.html b/servers/skel/docker-compose.d/custom/nginx/content/index.html new file mode 100644 index 0000000..e75cb97 --- /dev/null +++ b/servers/skel/docker-compose.d/custom/nginx/content/index.html @@ -0,0 +1,24 @@ + + + + + Welcome to nginx! + + + + +

Welcome to nginx!

+ Seems like this server is not setup! + + + \ No newline at end of file diff --git a/servers/skel/docker-compose.d/custom/nginx/entrypoint.sh b/servers/skel/docker-compose.d/custom/nginx/entrypoint.sh new file mode 100644 index 0000000..98f43ec --- /dev/null +++ b/servers/skel/docker-compose.d/custom/nginx/entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +trap exit TERM + +if [ -n "${CERTBOT_DOMAINS}" ]; then + echo "registering domains..." + + certbot --nginx -n --agree-tos \ + -m "${CERTBOT_EMAIL}" \ + -d "${CERTBOT_DOMAINS}" + + while :; do + echo "renewing domains..." + certbot --nginx -n renew + nginx -s reload + sleep 12h & wait $! + done & +else + echo "skipping certbot due to no domains!" +fi + +exec nginx -g "daemon off;" \ No newline at end of file diff --git a/servers/skel/docker-compose.d/custom/nginx/nginx.conf b/servers/skel/docker-compose.d/custom/nginx/nginx.conf new file mode 100644 index 0000000..5e076aa --- /dev/null +++ b/servers/skel/docker-compose.d/custom/nginx/nginx.conf @@ -0,0 +1,32 @@ + +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log notice; +pid /var/run/nginx.pid; + + +events { + worker_connections 1024; +} + + +http { + include /etc/nginx/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; + + keepalive_timeout 65; + + #gzip on; + + include /etc/nginx/conf.d/*.conf; +} diff --git a/servers/skel/docker-compose.d/docker-compose.yml b/servers/skel/docker-compose.d/docker-compose.yml new file mode 100644 index 0000000..c807fca --- /dev/null +++ b/servers/skel/docker-compose.d/docker-compose.yml @@ -0,0 +1,23 @@ +# I'm very comfortable in this version, therefore it's the standard +version: '2.2' + +services: + # default nginx setup + nginx: + build: custom/nginx + environment: + CERTBOT_EMAIL: "webmaster@ixvd.net" + CERTBOT_DOMAINS: "" + ports: + - 8080:80 + - 443:443 + networks: + - proxy + +# Here the default networks are defined +networks: + proxy: + external: true + internal: + external: true + \ No newline at end of file