From 928ad1422ff4a66bf8e04b8c574b684bcf1b0c0f Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Tue, 29 Mar 2022 16:01:16 +0200 Subject: [PATCH] Added Dockerfile & nginx configuration --- Dockerfile | 21 ++++++++++++++++ nginx/default.conf | 15 ++++++++++++ nginx/matrix.conf.template | 49 ++++++++++++++++++++++++++++++++++++++ nginx/nginx.conf | 37 ++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 Dockerfile create mode 100644 nginx/default.conf create mode 100644 nginx/matrix.conf.template create mode 100644 nginx/nginx.conf diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4b061a0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +FROM alpine:3.15.3 AS builder + +RUN apk update && \ + apk add --no-cache \ + hugo + +WORKDIR /app + +COPY . ./ + +# Build the site +RUN hugo + + +FROM nginx:1.21.6-alpine + +COPY nginx/nginx.conf /etc/nginx/nginx.conf +COPY nginx/default.conf /etc/nginx/conf.d/default.conf +COPY nginx/*.conf.template /etc/nginx/templates/ + +COPY --from=builder /app/public /usr/share/nginx/html diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100644 index 0000000..1c28faa --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,15 @@ +# vim: ft=nginx + +# =====FRONTEND HOSTING===== +location / { + root /usr/share/nginx/html; + index index.html; +} + +error_page 404 /404.html; + +# redirect server error pages to the static page /50x.html +error_page 500 502 503 504 /50x.html; +location = /50x.html { + root /usr/share/nginx/html; +} diff --git a/nginx/matrix.conf.template b/nginx/matrix.conf.template new file mode 100644 index 0000000..abc2879 --- /dev/null +++ b/nginx/matrix.conf.template @@ -0,0 +1,49 @@ +# vim: ft=nginx + +# =====MATRIX WELL-KNOWN FILES===== +# Used for server federation +location = /.well-known/matrix/server { + charset utf-8; + default_type application/json; + + if ($request_method = 'GET') { + add_header Access-Control-Allow-Origin '*'; + add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS'; + add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type, Authorization'; + + return 200 '{"m.server":"${MATRIX_SERVER}"}'; + } + + if ($request_method = 'OPTIONS') { + add_header Access-Control-Allow-Origin '*'; + add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS'; + add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type, Authorization'; + add_header 'Content-Length' 0; + return 204; + } + + return 405; +} + +location = /.well-known/matrix/client { + charset utf-8; + default_type application/json; + + if ($request_method = 'GET') { + add_header Access-Control-Allow-Origin '*'; + add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS'; + add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type, Authorization'; + + return 200 '{"m.homeserver":{"base_url":"${MATRIX_CLIENT_SERVER}"}}'; + } + + if ($request_method = 'OPTIONS') { + add_header Access-Control-Allow-Origin '*'; + add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS'; + add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type, Authorization'; + add_header 'Content-Length' 0; + return 204; + } + + return 405; +} diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 0000000..561a1bb --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,37 @@ +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; + + keepalive_timeout 65; + + gzip off; + + server { + listen 80; + listen [::]:80; + + # This order is important, as the Matrix matches should be evaluated first + include /etc/nginx/conf.d/matrix.conf; + include /etc/nginx/conf.d/default.conf; + } +}