From 8e4f94b33f23fe0f0e0d4ff8b49fa8cebfa97f0b Mon Sep 17 00:00:00 2001 From: Jatesadakarn Saengrat Date: Fri, 5 Jan 2018 18:56:30 +0700 Subject: [PATCH] Change nginx configuration based on BASE_URL, instead of moving actual files --- docker-run.sh | 9 ++------- nginx.conf | 5 +++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/docker-run.sh b/docker-run.sh index 39e25f20..fdbb95f4 100644 --- a/docker-run.sh +++ b/docker-run.sh @@ -2,6 +2,7 @@ set -e +BASE_URL=${BASE_URL:-/} NGINX_ROOT=/usr/share/nginx/html INDEX_FILE=$NGINX_ROOT/index.html @@ -22,13 +23,7 @@ replace_or_delete_in_index () { } if [ "${BASE_URL}" ]; then - NGINX_WITH_BASE_URL="${NGINX_ROOT}${BASE_URL}" - - mkdir -p ${NGINX_WITH_BASE_URL} - mv ${NGINX_ROOT}/*.* ${NGINX_WITH_BASE_URL}/ - - INDEX_FILE=$NGINX_WITH_BASE_URL/index.html - NGINX_ROOT=$NGINX_WITH_BASE_URL + sed -i "s|location .* {|location $BASE_URL {|g" /etc/nginx/nginx.conf fi replace_in_index myApiKeyXXXX123456789 $API_KEY diff --git a/nginx.conf b/nginx.conf index dda3d6de..94927db8 100644 --- a/nginx.conf +++ b/nginx.conf @@ -15,10 +15,11 @@ http { server { listen 8080; server_name localhost; + index index.html index.htm; location / { - root /usr/share/nginx/html; - index index.html index.htm; + alias /usr/share/nginx/html/; + if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';