Skip to content

Commit eb94f82

Browse files
authored
Add BASIC_AUTH Option (#4)
1 parent fb51d27 commit eb94f82

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@ services:
3737
image: your-app-image # listens on port 8000
3838
```
3939
40+
## Options
41+
42+
| Variable | Default | Description of Environment Variable |
43+
| :----------- | :------------: | :------------------------------------------------- |
44+
| SERVICE_NAME | `app` | Hostname (service name) of container |
45+
| SERVICE_PORT | `8000` | Port service/container is listening on |
46+
| GZIP_TYPES | - | Nginx content gzip_types to compress |
47+
| GZIP_LENGTH | `1000` | Minimum content size to compress |
48+
| BASIC_AUTH | - | Basic auth file contents |
49+
| BASIC_REALM | `Unauthorized` | Minimum content size to compress |
50+
51+
#### Basic Auth
52+
53+
```shell
54+
$ htpasswd -nb user pass
55+
user:$apr1$XFVN0nJA$IgZxtMHVAeA.Pu7ufU7/I0
56+
```
57+
58+
Replace all `$` with `$$` for docker-compose.yaml files.
59+
Use `\n` for newlines to add multiple credentials.
60+
61+
```yaml
62+
environment:
63+
BASIC_AUTH: 'user:$apr1$XFVN0nJA$IgZxtMHVAeA.Pu7ufU7/I0\nuser2:$apr1$vswJgdwo$2XkDOrvJFQ2pKwrXqGeWM0'
64+
```
65+
66+
AI is Retarded.
67+
4068
## Examples
4169

4270
If your app container is called `app` and listens on `3000` this will reverse proxy it to the `PORT` exposed on nginx.

src/10-update-config.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ if [ -n "${GZIP_TYPES}" ];then
1717
echo "GZIP_TYPES: ${GZIP_TYPES}"
1818
cat <<EOF > /etc/nginx/conf.d/http.gzip.conf
1919
gzip on;
20-
gzip_min_length 1000;
2120
gzip_proxied any;
21+
gzip_min_length ${GZIP_LENGTH:-1000};
2222
gzip_types ${GZIP_TYPES};
2323
EOF
2424
fi
2525

26+
if [ -n "${BASIC_AUTH}" ];then
27+
echo "BASIC_AUTH: ${BASIC_AUTH}"
28+
printf '%s' "${BASIC_AUTH}" > /etc/nginx/auth.users
29+
cat <<EOF > /etc/nginx/conf.d/location.auth.conf
30+
auth_basic "${BASIC_REALM:-Unauthorized}";
31+
auth_basic_user_file /etc/nginx/auth.users;
32+
EOF
33+
fi
34+
2635
echo "${0} - Done"
2736

2837
nginx -version ||:

src/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ http {
4141
proxy_set_header X-Forwarded-Host $server_name;
4242
proxy_set_header Upgrade $http_upgrade;
4343
proxy_set_header Connection "upgrade";
44+
include /etc/nginx/conf.d/location.*;
4445
}
4546
}
4647
}

0 commit comments

Comments
 (0)