From fcb958c5c0f904100ef90a5c07cb830bb3b85530 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 19 Jan 2022 12:31:35 +1100 Subject: [PATCH 1/2] Adds an option to enable nginx proxy for "dev mode" in docker - Commented out by default - No functional change unless code is un-commented in the docker-compose script --- docker/docker-compose.dev.yml | 22 ++++++++++++++ docker/nginx.dev.conf | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docker/nginx.dev.conf diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 14a9c4bbfc..c4691acdce 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -45,6 +45,10 @@ services: ports: # Expose web server on port 8000 - 8000:8000 + # Note: If using the inventree-dev-proxy container (see below), + # comment out the "ports" directive (above) and uncomment the "expose" directive + #expose: + # - 8000 volumes: # Ensure you specify the location of the 'src' directory at the end of this file - src:/home/inventree @@ -70,6 +74,24 @@ services: - dev-config.env restart: unless-stopped + ### Optional: Serve static and media files using nginx + ### Uncomment the following lines to enable nginx proxy for testing + #inventree-dev-proxy: + # container_name: inventree-dev-proxy + # image: nginx:stable + # depends_on: + # - inventree-dev-server + # ports: + # # Change "8000" to the port that you want InvenTree web server to be available on + # - 8000:80 + # volumes: + # # Provide ./nginx.conf file to the container + # # Refer to the provided example file as a starting point + # - ./nginx.dev.conf:/etc/nginx/conf.d/default.conf:ro + # # nginx proxy needs access to static and media files + # - src:/var/www + # restart: unless-stopped + volumes: # NOTE: Change "../" to a directory on your local machine, where the InvenTree source code is located # Persistent data, stored external to the container(s) diff --git a/docker/nginx.dev.conf b/docker/nginx.dev.conf new file mode 100644 index 0000000000..8fc47e622c --- /dev/null +++ b/docker/nginx.dev.conf @@ -0,0 +1,57 @@ + +server { + + # Listen for connection on (internal) port 80 + listen 80; + + location / { + # Change 'inventree-dev-server' to the name of the inventree server container, + # and '8000' to the INVENTREE_WEB_PORT (if not default) + proxy_pass http://inventree-dev-server:8000; + + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + + proxy_redirect off; + + client_max_body_size 100M; + + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_buffering off; + proxy_request_buffering off; + + } + + # Redirect any requests for static files + location /static/ { + alias /var/www/dev/static/; + autoindex on; + + # Caching settings + expires 30d; + add_header Pragma public; + add_header Cache-Control "public"; + } + + # Redirect any requests for media files + location /media/ { + alias /var/www/dev/media/; + + # Media files require user authentication + auth_request /auth; + } + + # Use the 'user' API endpoint for auth + location /auth { + internal; + + proxy_pass http://inventree-dev-server:8000/auth/; + + proxy_pass_request_body off; + proxy_set_header Content-Length ""; + proxy_set_header X-Original-URI $request_uri; + } + +} From f9ffbe322a74a8a5b3ac78c3c1fc605e7e894b5b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 19 Jan 2022 12:32:30 +1100 Subject: [PATCH 2/2] Adds note --- docker/docker-compose.dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index c4691acdce..ca0f837142 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -76,6 +76,7 @@ services: ### Optional: Serve static and media files using nginx ### Uncomment the following lines to enable nginx proxy for testing + ### Note: If enabling the proxy, change "ports" to "expose" for the inventree-dev-server container (above) #inventree-dev-proxy: # container_name: inventree-dev-proxy # image: nginx:stable