-
Notifications
You must be signed in to change notification settings - Fork 0
Nginx Service
The nginx service serves as the only point of entry for all HTTP traffic. By default it listens on port 80 for HTTP requests. Upon receiving such a request it will look into the nginx.conf file and forward it accordingly to internal services. This removes the need for different ports for the front- and backend while also enabling CORS by default.
The nginx server has three different targets the first rule that matches is used and they are routed as follows:
- /api: Is forwarded to the api.
- /grafana: Is forwarded to the grafana frontend. (Currently not implemented until Grafana is introduced)
- /: Remaining paths are send to astrapia.
The exact targets have to be specified in the .env file and are by default set to fennec:80, astrapia:3000. However when developing an application some services might not be run inside the docker network and instead on the host machine. Docker provides a built-in way to forward traffic from a docker container to the host through the hostname host.docker.internal.
The nginx configuration allows to change the target of each path to account for this. So by default the paths are routed as follows:
/api fennec:80
/grafana WIP
/ astrapia:3000
However in the case where Astrapia is hosted on the host machine the paths should be routed like so:
/api fennec:80
/grafana WIP
/ host.docker.internal:3000
The .env file has a nginx section where users can configure the targets individually, upon changing a target it is necessary to restart the container.
The possible values to change are and are routed as follows:
/api NGINX_FENNEC
/grafana NGINX_GRAFANA
/ NGINX_ASTRAPIA
Each of these variables can be changed in the .env file individually.
Since nginx handles all traffic and listens on port 80 by default simply accesing http://localhost is enough to gain access to the application.
The specific configuration can be found in the Docker/nginx/nginx.template.conf file. The targets are environment variables to allow the configuration of targets between configuration. However nginx does not allow dynamic routing through environment variables to work around this limitation the service uses the envsubst utility to replace the environment variables before writing the file as proper nginx.conf file into the nginx directory.