add/improve proxy/port args
[basic-https-conf] / nginx-site
index 937c71aa7693ce36f3f2254b1c5f3114927fa706..2869e44a87e2980a1ecfcc4f2a4ffa259b238c78 100755 (executable)
@@ -31,8 +31,8 @@ location for storing certs.
 EXTRA_SETTINGS_FILE can be - for stdin
 -c CERT_DIR       In priority: this arg, $ACME_TINY_WRAPPER_CERT_DIR,
                   $HOME/webservercerts, if the other options aren't set.
+-f [ADDR:]PORT    Enable proxy to [ADDR:]PORT. ADDR default is 127.0.0.1
 -p PORT           Port to listen on, default 443
--f PORT           Enable proxy to PORT on localhost
 -r                DocumentRoot
 -h|--help         Print help and exit
 
@@ -50,15 +50,14 @@ if [[ ! $cert_dir ]]; then
     cert_dir=$HOME/webservercerts
 fi
 port=443
-proxy_port=
 extra_settings=
 temp=$(getopt -l help: c:f:p:r:h "$@") || usage 1
 eval set -- "$temp"
 while true; do
     case $1 in
         -c) cert_dir="$2"; shift 2 ;;
+        -f) proxy="$2"; shift 2 ;;
         -p) port="$2"; shift 2 ;;
-        -f) proxy_port="$2"; shift 2 ;;
         -r) root="$2"; shift 2 ;;
         --) shift; break ;;
         -h|--help) usage ;;
@@ -81,6 +80,10 @@ if [[ ! $root ]]; then
     root=/var/www/$h/html
 fi
 
+if [[ $proxy ]]; then
+    [[ $proxy == *:* ]] || proxy=127.0.0.1:$proxy
+fi
+
 
 ##### end command line parsing ########
 
@@ -138,7 +141,7 @@ if [[ $extra_settings ]]; then
     cat $extra_settings >>/etc/nginx/sites-enabled/$h.conf
 fi
 
-if [[ $proxy_port ]]; then
+if [[ $proxy ]]; then
     cat >>/etc/nginx/sites-enabled/$h.conf <<EOF
     location / {
         proxy_set_header Host \$host;
@@ -146,7 +149,7 @@ if [[ $proxy_port ]]; then
         proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Ssl on;
         proxy_set_header X-Forwarded-Port $port;
-        proxy_pass http://127.0.0.1:$proxy_port;
+        proxy_pass http://$proxy;
     }
 EOF
 fi