Skip to content

Commit e492fbc

Browse files
authored
Add try_files and 404 (#2)
1 parent d74af7e commit e492fbc

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Coming Soon...
3030
| STATIC | /static | Nginx root directory |
3131
| SUID | 1000 | Directory group/user ID |
3232
| NGINX_INDEX | `index.html index.htm` | Nginx directory index files |
33+
| ERROR_PAGE | `/404.html` | Nginx 404 page, set `off` to disable |
3334
| GZIP_TYPES | `*` | Nginx gzip_types, set `off` to disable |
3435
| GZIP_LENGTH | `1000` | Minimum content size to compress |
3536
| BASIC_AUTH | - | Basic auth file contents |

src/10-setup.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,31 @@ echo "NGINX_INDEX: ${NGINX_INDEX:=$_NGINX_INDEX}"
1414
sed "s/NGINX_INDEX/${NGINX_INDEX:=$_NGINX_INDEX}/g" \
1515
-i /etc/nginx/nginx.conf
1616

17+
rm -f /etc/nginx/conf.d/http.gzip.conf
18+
rm -f /etc/nginx/conf.d/location.auth.conf
19+
rm -f /etc/nginx/auth.users
20+
1721
: "${GZIP_TYPES:=*}"
1822
echo "GZIP_TYPES: ${GZIP_TYPES}"
1923
if [ "${GZIP_TYPES}" != "off" ];then
20-
cat <<EOF > /etc/nginx/conf.d/http.gzip.conf
24+
cat <<EOF >> /etc/nginx/conf.d/http.gzip.conf
2125
gzip on;
2226
gzip_proxied any;
2327
gzip_min_length ${GZIP_LENGTH:-1000};
2428
gzip_types ${GZIP_TYPES};
2529
EOF
2630
fi
2731

32+
: "${ERROR_PAGE:=/404.html}"
33+
if [ "${ERROR_PAGE}" != "off" ];then
34+
echo "ERROR_PAGE: ${ERROR_PAGE}"
35+
echo "error_page 404 ${ERROR_PAGE};" >> /etc/nginx/conf.d/location.auth.conf
36+
fi
37+
2838
if [ -n "${BASIC_AUTH}" ];then
2939
echo "BASIC_AUTH: ${BASIC_AUTH}"
3040
printf '%s' "${BASIC_AUTH}" > /etc/nginx/auth.users
31-
cat <<EOF > /etc/nginx/conf.d/location.auth.conf
41+
cat <<EOF >> /etc/nginx/conf.d/location.auth.conf
3242
auth_basic "${BASIC_REALM:-Unauthorized}";
3343
auth_basic_user_file /etc/nginx/auth.users;
3444
EOF

src/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ http {
2626
root /static;
2727
index NGINX_INDEX;
2828
autoindex on;
29+
try_files $uri $uri.html $uri/ =404;
2930
include /etc/nginx/conf.d/location.*;
3031
}
3132
}

0 commit comments

Comments
 (0)