-
Notifications
You must be signed in to change notification settings - Fork 0
Docker Nginx Local
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.
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
cd front/docker
bash docker.sh buildThis will:
- prompt you for env variables
- generate NGINX, Supervisord and Gunicorn configs from templates
- build all the docker containers
- run the docker containers.
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.
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=redisComment 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" ]In theory, you don't need to change the build pipeline.
cd front/docker
bash docker.sh buildSeveral 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
nginx_external.conf is useless: we want to access the site on localhost, while nginx_external exposes the host server to HTTPs.
I.E., that
-
server/server_nameislocalhost -
server/locationuses the Docker container names, so that docker can properly redirect requests to containers.
Connect to http://localhost:$NGINX_PORT (default nginx port is 8080).