diff --git a/nginx-grpc.tpl b/nginx-grpc.tpl index 0541900..2e3a1e7 100644 --- a/nginx-grpc.tpl +++ b/nginx-grpc.tpl @@ -6,4 +6,7 @@ client_body_timeout 1071906480m; grpc_read_timeout 1071906480m; grpc_pass grpc://HOST:PORT; + grpc_set_header Host $host; + grpc_set_header X-Real-IP $remote_addr; + grpc_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } \ No newline at end of file diff --git a/nginx-proxy.tpl b/nginx-proxy.tpl index a1bc622..d6ec8bf 100644 --- a/nginx-proxy.tpl +++ b/nginx-proxy.tpl @@ -1,3 +1,6 @@ location LOCATION { - proxy_pass http://HOST:PORT; + proxy_pass http://HOST:PORT; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } \ No newline at end of file diff --git a/nginx-ws.tpl b/nginx-ws.tpl index 8c01404..062fc7f 100644 --- a/nginx-ws.tpl +++ b/nginx-ws.tpl @@ -2,12 +2,11 @@ if ($http_upgrade != "websocket") { return 404; } - proxy_redirect off; - proxy_pass http://HOST:PORT; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_redirect off; + proxy_pass http://HOST:PORT; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } \ No newline at end of file diff --git a/server-nginx.sh b/server-nginx.sh index 8819230..b3547af 100755 --- a/server-nginx.sh +++ b/server-nginx.sh @@ -8,10 +8,10 @@ NGCONF="/etc/nginx/nginx.conf" usage() { echo "server-nginx --ng-server [,p=443] --ng-proxy [,h=127.0.0.1]" - echo " --ng-server [,p=443]" echo " --ng-proxy [,h=127.0.0.1][,d=host-domain]" - echo " --st-port " + echo " --ng-server [,p=443]" echo " --st-map " + echo " --st-port " } TEMP=`getopt -o m:p:s:x: --long ng-server:,ng-proxy:,st-map:,st-port: -n "$0" -- $@` @@ -48,7 +48,11 @@ while true ; do esac done -if [ -z "${NGSVR}" ] && [ -z "${STPORT}" ]; then echo "No server/stream defined. Quit."; exit 1; fi +if [ -z "${NGSVR}" ] && [ -z "${STPORT}" ]; then + echo "No server/stream defined. Quit."; + usage; + exit 1; +fi # Running as root to enable low port listening. Necessary for Fargate or k8s. # sed -i 's/^user nginx;$/user root;/g' /etc/nginx/nginx.conf @@ -59,11 +63,12 @@ if [ -f /etc/nginx/conf.d/default.conf ]; then mv default.conf default.conf.disable fi +# Remove all lines generated previously after #STSTUB tag. +sed -i '/\#STSTUB/q' /etc/nginx/nginx.conf +# Remove #STSTUB tag +sed -i '/\#STSTUB/d' /etc/nginx/nginx.conf + if [ -n "${STPORT}" ]; then - # Remove all lines generated previously after #STSTUB tag. - sed -i '/\#STSTUB/q' /etc/nginx/nginx.conf - # Remove #STSTUB tag - sed -i '/\#STSTUB/d' /etc/nginx/nginx.conf rm /tmp/map.conf rm /tmp/ups.conf # Attach the stream configuration to the tail of nginx.conf