Skip to content

Commit

Permalink
use proxy to put everything behind the same address
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jun 21, 2024
1 parent dba13e0 commit 1c5e295
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,21 @@ services:
hostname: nginx
profiles:
- dev
build:
context: ./nginx
volumes:
- ./media:/media_files
ports:
- 8000:80

nginx-maps:
hostname: nginx
profiles:
- maps
build:
context: ./nginx
args:
- TEMPLATE_NAME=maps
volumes:
- ./media:/media_files
ports:
Expand Down
4 changes: 3 additions & 1 deletion nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM nginx:1.23

COPY default.conf.template /etc/nginx/templates/default.conf.template
ARG TEMPLATE_NAME=default

COPY ${TEMPLATE_NAME}.conf.template /etc/nginx/templates/default.conf.template
RUN mkdir /statics /media_files
112 changes: 112 additions & 0 deletions nginx/maps.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

upstream django {
server django:8000;
keepalive 64;
}

upstream maps {
server maps:80;
keepalive 64;
}

upstream titiler {
server titiler:8000;
keepalive 64;
}


server {
listen 80;
resolver 127.0.0.11;

#access_log /var/log/nginx/host.access.log main;

#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;
}

client_max_body_size 300m;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Cookie $http_cookie;
proxy_redirect off;

location /static/ {
alias /statics/;
try_files $uri @proxy;
}

location /media/ {
alias /media_files/;
add_header 'Access-Control-Allow-Origin' '*';
}

location /geoapi/static/ {
alias /statics/geoapi/;
try_files $uri @proxy;
}

location @proxy {
proxy_pass http://django;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location /titiler/ {
proxy_pass http://titiler;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location /admin/ {
# TODO: use a better solution to upload files, for example s3 + tusd
# allow upload of big file - this is a temporary solution
client_max_body_size 8000M;
client_body_buffer_size 8000M;
client_body_timeout 360;

proxy_pass http://django;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location /api/ {
# TODO: use a better solution to upload files, for example s3 + tusd
# allow upload of big file - this is a temporary solution
client_max_body_size 8000M;
client_body_buffer_size 8000M;
client_body_timeout 360;

proxy_pass http://django;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}

location / {
proxy_pass http://maps;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
}
}
5 changes: 2 additions & 3 deletions nginx/maps.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// const BASE_URL = "http://localhost:8000
const BASE_URL = `http://${window.location.hostname}:8000`
const BASE_URL = window.location.origin

window.API_URL = `${BASE_URL}/api/maps/`;
window.API_URL = `/api/maps/`;
window.PORTAL_KEY = "34005d2a-5d57-470b-98d9-9ed119a265b9"

window.TRANSFORM_REQUEST = (url, resourceType) => {
Expand Down

0 comments on commit 1c5e295

Please sign in to comment.