Skip to content

Commit 4fd031e

Browse files
committed
Initial commit
0 parents  commit 4fd031e

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!Dockerfile
3+
!files/run.sh
4+
!files/nginx.conf.tmpl

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM nginx:1.11.9-alpine
2+
3+
# for htpasswd command
4+
RUN apk add --no-cache --update \
5+
apache2-utils
6+
7+
ENV WORKER_PROCESSES auto
8+
9+
COPY files/run.sh /
10+
COPY files/nginx.conf.tmpl /
11+
12+
ENTRYPOINT ["/run.sh"]

files/nginx.conf.tmpl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
user nginx;
2+
worker_processes ##WORKER_PROCESSES##;
3+
4+
error_log /dev/stdout info;
5+
pid /var/run/nginx.pid;
6+
7+
events {
8+
worker_connections 1024;
9+
}
10+
11+
http {
12+
access_log /dev/stdout;
13+
14+
server {
15+
listen 80;
16+
server_name ##SERVER_NAME##;
17+
18+
location / {
19+
proxy_pass ##PROXY_PASS##;
20+
auth_basic "Restricted";
21+
auth_basic_user_file /etc/nginx/.htpasswd;
22+
23+
# Do not pass Authorization header to destination
24+
proxy_set_header Authorization "";
25+
}
26+
}
27+
}

files/run.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ -z $BASIC_AUTH_USERNAME ]; then
6+
echo >&2 "BASIC_AUTH_USERNAME must be set"
7+
exit 1
8+
fi
9+
10+
if [ -z $BASIC_AUTH_PASSWORD ]; then
11+
echo >&2 "BASIC_AUTH_PASSWORD must be set"
12+
exit 1
13+
fi
14+
15+
if [ -z $SERVER_NAME ]; then
16+
echo >&2 "SERVER_NAME must be set"
17+
exit 1
18+
fi
19+
20+
if [ -z $PROXY_PASS ]; then
21+
echo >&2 "PROXY_PASS must be set"
22+
exit 1
23+
fi
24+
25+
htpasswd -bBc /etc/nginx/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
26+
sed \
27+
-e "s/##WORKER_PROCESSES##/$WORKER_PROCESSES/g" \
28+
-e "s/##SERVER_NAME##/$SERVER_NAME/g" \
29+
-e "s|##PROXY_PASS##|$PROXY_PASS|g" \
30+
nginx.conf.tmpl > /etc/nginx/nginx.conf
31+
32+
nginx -g "daemon off;"

0 commit comments

Comments
 (0)