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