Skip to content

Commit b6a9716

Browse files
add nginx basic authentication
1 parent 2c321aa commit b6a9716

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ RUN apk add --no-cache \
2121
tini \
2222
wget \
2323
curl \
24+
apache2-utils\
2425
libmaxminddb \
2526
ncurses && \
2627
rm -rf /var/lib/apt/lists/* && \
@@ -33,6 +34,7 @@ COPY /resources/goaccess/GeoLite2-City.mmdb /goaccess-config/GeoLite2-City.mmdb
3334
# set up nginx
3435
COPY /resources/nginx/index.html /var/www/html/index.html
3536
COPY /resources/nginx/nginx.conf /etc/nginx/nginx.conf
37+
ADD /resources/nginx/.htpasswd /opt/auth/.htpasswd
3638

3739
COPY /resources/scripts/start.sh /start.sh
3840
VOLUME ["/opt/log"]

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ goaccess:
4242
restart: always
4343
environment:
4444
- TZ=America/New_York
45-
- SKIP_ARCHIVED_LOGS=False #optional
45+
- SKIP_ARCHIVED_LOGS=False #optional
46+
- BASIC_AUTH=False #optional
47+
- BASIC_AUTH_USERNAME=user #optional
48+
- BASIC_AUTH_PASSWORD=pass #optional
4649
ports:
4750
- '7880:7880'
4851
volumes:
@@ -62,12 +65,18 @@ goaccess:
6265
- PUID=0
6366
- PGID=0
6467
- TZ=America/New_York
65-
- SKIP_ARCHIVED_LOGS=False #optional
68+
- SKIP_ARCHIVED_LOGS=False #optional
69+
- BASIC_AUTH=False #optional
70+
- BASIC_AUTH_USERNAME=user #optional
71+
- BASIC_AUTH_PASSWORD=pass #optional
6672
```
6773
6874
| Parameter | Function |
6975
|-----------|----------|
7076
| `-e SKIP_ARCHIVED_LOGS=True/False` | (Optional) Defaults to False. Set to True to skip archived logs, i.e. proxy-host*.gz |
77+
| `-e BASIC_AUTH=True/False` | (Optional) Defaults to False. Set to True to enable nginx basic authentication. |
78+
| `-e BASIC_AUTH_USERNAME=user` | (Optional) Requires BASIC_AUTH to bet set to True. Username for basic authentication. |
79+
| `-e BASIC_AUTH_PASSWORD=pass` | (Optional) Requires BASIC_AUTH to bet set to True. Password for basic authentication. |
7180

7281
Thanks to https://github.com/GregYankovoy for the inspiration, and for their nginx.conf :)
7382

resources/nginx/.htpasswd

Whitespace-only changes.

resources/nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ http {
2424
access_log off;
2525

2626
location / {
27+
#goan_authbasic
2728
try_files /nonexistent @$type;
2829
}
2930

resources/scripts/start.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
#!/bin/bash
22

3+
#BEGIN - Set NGINX basic authentication
4+
if [[ "${BASIC_AUTH}" == "True" ]]
5+
then
6+
echo "Setting up basic auth in NGINX..."
7+
if [[ -z "$BASIC_AUTH_USERNAME" || -z "$BASIC_AUTH_PASSWORD" ]]
8+
then
9+
echo "Username or password is blank or not set."
10+
else
11+
nginx_auth_basic_s="#goan_authbasic"
12+
nginx_auth_basic_r="auth_basic \"GoAccess WebUI\";\n auth_basic_user_file \/opt\/auth\/.htpasswd; \n"
13+
sed -i "s/$nginx_auth_basic_s/$nginx_auth_basic_r/" /etc/nginx/nginx.conf
14+
15+
htpasswd -b /opt/auth/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
16+
fi
17+
fi
18+
#END - Set NGINX basic authentication
19+
320
#BEGIN - Load archived logs
421
if [[ "${SKIP_ARCHIVED_LOGS}" == "True" ]]
522
then

0 commit comments

Comments
 (0)