From 5af30051793849fa17846be69245d90398dc56e3 Mon Sep 17 00:00:00 2001 From: = <=> Date: Thu, 7 Mar 2024 12:16:19 +1100 Subject: [PATCH] feat: enable API_URL in Dockerfile fix tranga.conf not redirecting /api/ requests --- Dockerfile | 1 + nginx/conf.d/tranga.conf | 52 --------------------------- nginx/templates/default.conf.template | 29 +++++++++++++++ 3 files changed, 30 insertions(+), 52 deletions(-) delete mode 100644 nginx/conf.d/tranga.conf create mode 100644 nginx/templates/default.conf.template diff --git a/Dockerfile b/Dockerfile index 6f11182..9a9592a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,4 +2,5 @@ COPY ./Website /usr/share/nginx/html COPY ./nginx /etc/nginx EXPOSE 80 +ENV API_URL=http://tranga-api:6531 CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/nginx/conf.d/tranga.conf b/nginx/conf.d/tranga.conf deleted file mode 100644 index fbc3270..0000000 --- a/nginx/conf.d/tranga.conf +++ /dev/null @@ -1,52 +0,0 @@ -server { - listen 80; - listen [::]:80; - server_name localhost; - - #access_log /var/log/nginx/host.access.log main; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } - - location ~ /api/ { - proxy_pass_request_headers on; - set $upstream_app tranga-api; - set $upstream_port 6531; - set $upstream_proto http; - proxy_pass $upstream_proto://$upstream_app:$upstream_port; - } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } - - # proxy the PHP scripts to Apache listening on 127.0.0.1:80 - # - #location ~ \.php$ { - # proxy_pass http://127.0.0.1; - #} - - # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 - # - #location ~ \.php$ { - # root html; - # fastcgi_pass 127.0.0.1:9000; - # fastcgi_index index.php; - # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; - # include fastcgi_params; - #} - - # deny access to .htaccess files, if Apache's document root - # concurs with nginx's one - # - #location ~ /\.ht { - # deny all; - #} -} \ No newline at end of file diff --git a/nginx/templates/default.conf.template b/nginx/templates/default.conf.template new file mode 100644 index 0000000..cf526c7 --- /dev/null +++ b/nginx/templates/default.conf.template @@ -0,0 +1,29 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + + http2 on; + + server_name _; + + access_log /dev/stdout main; + error_log /dev/stderr; + + location /api/ { + proxy_pass_request_headers on; + rewrite ^/api/(.*)$ /$1 break; + proxy_pass $API_URL; + } + + location / { + root /usr/share/nginx/html; + index index.html index.htm; + } + + # redirect server error pages to the static page /50x.html + # + error_page 500 502 503 504 /50x.html; + location = /50x.html { + root /usr/share/nginx/html; + } +} \ No newline at end of file