aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/nginx-dev
diff options
context:
space:
mode:
Diffstat (limited to '.local/share/bin/nginx-dev')
-rwxr-xr-x.local/share/bin/nginx-dev47
1 files changed, 44 insertions, 3 deletions
diff --git a/.local/share/bin/nginx-dev b/.local/share/bin/nginx-dev
index f135cf6..f67a0ff 100755
--- a/.local/share/bin/nginx-dev
+++ b/.local/share/bin/nginx-dev
@@ -1,9 +1,47 @@
#!/bin/sh
+folder="$PWD"
port=8080
-config="$(mktemp)"
-pidfile="$(mktemp)"
try_files='/$uri /$uri.html /$uri/index.html =404'
+cache_control='
+ add_header Last-Modified $date_gmt;
+ add_header Cache-Control "private no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0";
+ if_modified_since off;
+ expires off;
+ etag off;
+'
+
+usage() {
+ cat << EOF
+usage: $(basename "$0") [options] [folder]
+
+options:
+ -p PORT host server on port PORT (default $port)
+ -t STR set try_files pattern to STR (default '$try_files')
+ -C enable server cache (disabled by default)
+ -v verbose mode (prints config before starting server)
+ -h show this help
+EOF
+exit $1
+}
+
+ARGC=0
+while getopts hvp:Ct: OPT; do
+ [ $OPTIND -gt $ARGC ] && ARGC=$OPTIND
+ case $OPT in
+ h) usage 0 ;;
+ p) port="$OPTARG" ;;
+ t) try_files="$OPTARG" ;;
+ v) print_config=1 ;;
+ C) cache_control="" ;;
+ \?|*) usage 1 ;;
+ esac
+done
+shift $(( $OPTIND - 1 ))
+[ $# -ge 1 ] && folder="$(readlink -f "$1")"
+
+config="$(mktemp)"
+pidfile="$(mktemp)"
cat << EOF > "$config"
worker_processes 1;
daemon off;
@@ -18,6 +56,8 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
+ $cache_control
+
access_log /dev/stdout;
server {
@@ -32,6 +72,7 @@ http {
}
}
EOF
+[ $print_config ] && cat "$config"
nginx -c "$config"
-
rm -f "$config" "$pidfile"
+