Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .gitignore

This file was deleted.

6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM nginx:1.11.10

COPY nginx.conf /etc/nginx/nginx.conf
COPY bin/* /usr/local/bin/
COPY default.conf /etc/nginx/conf.d/default.conf
COPY bin/entry.sh /usr/local/bin/

RUN chmod 744 /usr/local/bin/entry.sh && \
chown root:root /usr/local/bin/entry.sh

CMD ["/usr/local/bin/entry.sh"]
CMD /usr/local/bin/entry.sh
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# nginx-basic-auth
A simple nginx template for challenging basic auth

A simple nginx template for challenging basic auth. See docker-compose.yml for example of usage.
22 changes: 13 additions & 9 deletions bin/entry.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
#!/bin/bash

# Providing defaults values for missing env variables
[ "$DEFAULT_USER" = "" ] && export DEFAULT_USER="admin"
[ "$DEFAULT_PASSWORD" = "" ] && export DEFAULT_PASSWORD="$(openssl rand -base64 12)"
touch /htpasswd

printf "$DEFAULT_USER:$(openssl passwd -crypt "${DEFAULT_PASSWORD}")\n" > /htpasswd
i=0
user=${USER_0}
password=${PASSWORD_0}

echo "=====[ Nginx Basic Auth ]============================================"
echo "Generated default user"
echo "Login: $DEFAULT_USER"
echo "Password: $DEFAULT_PASSWORD"
echo "=========================================================================="
while [ "$user" ]; do
printf "$user:$(openssl passwd -crypt "$password")\n" >> /htpasswd

let "i += 1"
user_var_name="USER_$i"
user=${!user_var_name}
password_var_name="PASSWORD_$i"
password=${!password_var_name}
done

nginx -g "daemon off;"
15 changes: 15 additions & 0 deletions default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
server {
listen 80;

location / {
auth_basic "Are you authorized to be there?";
auth_basic_user_file /htpasswd;

try_files DUMMY @return200;
}

location @return200 {
add_header Content-Type text/plain;
return 200 'Welcome';
}
}
9 changes: 9 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
nginx-basic-auth:
build: .
ports:
- 80:80
environment:
USER_0: user0
PASSWORD_0: test0
USER_1: user1
PASSWORD_1: test1
60 changes: 0 additions & 60 deletions nginx.conf

This file was deleted.