Skip to content

Docker Nginx Local

paulhectork edited this page Feb 27, 2026 · 6 revisions

Local usage of the app in Docker with Nginx

In general, Docker and Nginx are used for prod builds.

Here is how to use Docker and Nginx to build the app and access it with http://localhost:8080.

This assumes you are familiar with Docker deploy and have all the necessary packages installed on your server.


Prod Docker deploy, in short

Setup

We use

  • a docker-compose with an nginx service that is configured to do routing between docker components
  • an nginx server on our host that exposes your app through HTTPS.

So basically: Nginx -> Docker -> Nginx -> Other containers

Workflow

cd front/docker
bash docker.sh build

This will:

  • prompt you for env variables
  • generate NGINX, Supervisord and Gunicorn configs from templates
  • build all the docker containers
  • run the docker containers.

Changes for localhost

In short,

  • the host nginx server is useless
  • the django settings must be updated to work locally
  • all HOSTS in your .env files must have the names of containers, not URIs.
  • PROD_URL in your .env must be localhost.

Run docker locally

1. .env variables

Note: only relevant variables are included. In short, set DOCKER=True, PROD_URL=localhost and all *_HOST variables to their docker-compose container name.

# front/app/config/.env

TARGET=prod
DOCKER=True
C_FORCE_ROOT=True
MEDIA_DIR=/data/mediafiles
PROD_URL=localhost  # !! this is important
REDIS_HOST=redis
MONGODB_HOST=redis
AIIINOTATE_HOST=aiiinotate
MIRADOR_HOST=mirador
# font/docker/.env

REDIS_HOST=redis

2. Update your Django settings (front/app/config/settings/base.py)

Comment this block:

ALLOWED_HOSTS = hosts + https_hosts + wildcard_hosts
CSRF_TRUSTED_ORIGINS = https_hosts + wildcard_hosts
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")

Add this block:

USE_X_FORWARDED_HOST = True
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False
ALLOWED_HOSTS = ["localhost", "127.0.0.1", "web"]
CSRF_TRUSTED_ORIGINS = [ "http://localhost:8080" ]

3. Build your containers

In theory, you don't need to change the build pipeline.

cd front/docker
bash docker.sh build

3. Nginx

Several nginx templates are generated. The two main are:

  • nginx.conf: internal nginx for the Docker compose
  • nginx_external.conf: nginx conf for the host server

a. Don't update your nginx host server !

nginx_external.conf is useless: we want to access the site on localhost, while nginx_external exposes the host server to HTTPs.

b. Ensure your nginx.conf is valid

I.E., that

  • server/server_name is localhost
  • server/location uses the Docker container names, so that docker can properly redirect requests to containers.

4. Done !!

Connect to http://localhost:$NGINX_PORT (default nginx port is 8080).

Clone this wiki locally