diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-25 16:07:25 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-25 16:07:25 +0100 |
commit | 3155f89d80d33afe28aa5f41aa68cd5123d17576 (patch) | |
tree | c804e35e18956968e3f3f5421ca34832d351c9f0 /.local/share/bin | |
parent | 854fb8c1705a52707d0b2b1ad6f9f7391c2f9267 (diff) |
update nginx-dev script
Diffstat (limited to '.local/share/bin')
-rwxr-xr-x | .local/share/bin/nginx-dev | 47 |
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" + |