From 3ef9d3459dbccb665b24ee1d221d0e227ef7953e Mon Sep 17 00:00:00 2001 From: Brad Treloar Date: Mon, 3 Feb 2025 00:26:07 +1030 Subject: [PATCH] Add server --- Dockerfile | 11 +++++++++++ README.md | 18 +++++++++++++++++- nginx.conf | 9 +++++++++ nginx.htpasswd | 1 + passwd.sh | 4 ++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 nginx.conf create mode 100644 nginx.htpasswd create mode 100755 passwd.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e051d7d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM nginx:alpine + +# Replace default config. +RUN rm /etc/nginx/conf.d/default.conf +COPY nginx.conf /etc/nginx/conf.d/auth.conf + +# Add user credentials. +COPY nginx.htpasswd /etc/nginx/auth.htpasswd + +# Copy the HTML files. +COPY ./site /usr/share/nginx/html diff --git a/README.md b/README.md index 2b8c224..efa8bd9 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ -# My notes +# Notes server +## Build and run + +```bash +# Build/rebuild the image. +docker build --no-cache -t notes-server . + +# Run the image, listening on port 8080. +docker run -p 8080:80 -t notes-server +``` + +## Auth credentials setup + +```bash +# Overwrite the htpasswd file with new user credentials. +htpasswd -nb username password > auth.htpasswd +``` diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..2595c9a --- /dev/null +++ b/nginx.conf @@ -0,0 +1,9 @@ +server { + listen 80 default_server; + root "/usr/share/nginx/html"; + + location / { + auth_basic "Restricted"; + auth_basic_user_file auth.htpasswd; + } +} diff --git a/nginx.htpasswd b/nginx.htpasswd new file mode 100644 index 0000000..ed120f1 --- /dev/null +++ b/nginx.htpasswd @@ -0,0 +1 @@ +biggus:$apr1$1UKr.9xY$x9U2kFbzIkMAr215vDgqq/ diff --git a/passwd.sh b/passwd.sh new file mode 100755 index 0000000..fe37844 --- /dev/null +++ b/passwd.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +# htpasswd from package apache2-utils +htpasswd -nb $1 $2 > auth.htpasswd