Skip to content

Commit 44a5080

Browse files
committed
Initial commit
0 parents  commit 44a5080

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sudo: required
2+
3+
services:
4+
- docker
5+
6+
script:
7+
- docker build -t nginx-basic-auth .

Dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM nginx:alpine
2+
3+
ENV HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \
4+
FORWARD_PORT=80
5+
6+
WORKDIR /opt
7+
8+
RUN apk add --no-cache gettext
9+
10+
COPY auth.conf auth.htpasswd launch.sh ./
11+
12+
CMD ["./launch.sh"]

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[![Travis](https://shields.beevelop.com/travis/beevelop/docker-nginx-basic-auth.svg?style=flat-square)](https://travis-ci.org/beevelop/docker-nginx-basic-auth)
2+
[![Docker Pulls](https://shields.beevelop.com/docker/pulls/beevelop/nginx-basic-auth.svg?style=flat-square)](https://links.beevelop.com/d-nginx-basic-auth)
3+
[![ImageLayers Size](https://shields.beevelop.com/imagelayers/image-size/beevelop/nginx-basic-auth/latest.svg?style=flat-square)](https://imagelayers.io/?images=beevelop/nginx-basic-auth:latest)
4+
[![ImageLayers Layers](https://shields.beevelop.com/imagelayers/layers/beevelop/nginx-basic-auth/latest.svg?style=flat-square)](https://imagelayers.io/?images=beevelop/nginx-basic-auth:latest)
5+
![Badges](https://shields.beevelop.com/badge/badges-6-brightgreen.svg?style=flat-square)
6+
[![Beevelop](https://links.beevelop.com/honey-badge)](https://beevelop.com)
7+
8+
# nginx-basic-auth
9+
----
10+
> Simple Docker image to provide basic authentication for a single other container.
11+
12+
## Quickstart
13+
```
14+
docker run -d --name web dockercloud/hello-world
15+
docker run -d -p 80:80 --link web:web --name auth beevelop/nginx-basic-auth
16+
```
17+
18+
Try accessing and logging in with username `foo` and password `bar`.
19+
20+
## Advanced
21+
```
22+
docker run -d -e HTPASSWD='' -e FORWARD_PORT=1337 --link web:web -p 8080:80 --name auth beevelop/nginx-basic-auth
23+
```
24+
> Use single quotes to prevent unwanted interpretation of `$` signs!
25+
26+
## Configuration
27+
- `HTPASSWD` (default: `foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.`): Will be written on launch to the .htpasswd file (non-persistent)
28+
- `FORWARD_PORT` (default: `80`): Port of the source container that should be forwarded
29+
30+
## Troubleshooting
31+
```
32+
nginx: [emerg] host not found in upstream "web" in /etc/nginx/conf.d/auth.conf:80
33+
```
34+
- You need to link the container as `web` (`--link foobar:web`)
35+
---
36+
- SSL is unsupported ATM, but might be available in the near future. For now it might be a suitable solution to use another reverse proxy (e.g. `jwilder/nginx-proxy`) that acts as a central gateway. You just need to configure the `VIRTUAL_HOST` env and disable port forwarding.

auth.conf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
server {
2+
listen 80 default_server;
3+
4+
location / {
5+
auth_basic "Restricted";
6+
auth_basic_user_file auth.htpasswd;
7+
8+
proxy_pass http://web:${FORWARD_PORT};
9+
proxy_read_timeout 900;
10+
}
11+
}

auth.htpasswd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
${HTPASSWD}

launch.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
3+
envsubst < auth.conf > /etc/nginx/conf.d/auth.conf
4+
envsubst < auth.htpasswd > /etc/nginx/auth.htpasswd
5+
6+
nginx -g "daemon off;"

0 commit comments

Comments
 (0)