It seems someone from ERPNext already answered this question on ERPNext Discuss Forum. I'm going to copy the solution here for future reference.
- Add following labels to
erpnext-nginx
service
- "traefik.http.routers.erpnext-nginx.rule=HostRegexp(`{catchall:.*}`)"
- "traefik.http.middlewares.erpnext-nginx.headers.customrequestheaders.Host=erpnext-nginx"
- "traefik.http.routers.erpnext-nginx.middlewares=erpnext-nginx"
to get the following configuration of the service:
erpnext-nginx:
image: frappe/erpnext-nginx:${ERPNEXT_VERSION}
restart: on-failure
environment:
- FRAPPE_PY=erpnext-python
- FRAPPE_PY_PORT=8000
- FRAPPE_SOCKETIO=frappe-socketio
- SOCKETIO_PORT=9000
labels:
- "traefik.enable=true"
- "traefik.http.routers.erpnext-nginx.rule=Host(${SITES})"
- "${ENTRYPOINT_LABEL}"
- "${CERT_RESOLVER_LABEL}"
- "traefik.http.services.erpnext-nginx.loadbalancer.server.port=80"
- "traefik.http.routers.erpnext-nginx.rule=HostRegexp(`{catchall:.*}`)"
- "traefik.http.middlewares.erpnext-nginx.headers.customrequestheaders.Host=erpnext-nginx"
- "traefik.http.routers.erpnext-nginx.middlewares=erpnext-nginx"
volumes:
- sites-vol:/var/www/html/sites:rw
- assets-vol:/assets:rw
- Copy
env-local
to .env
and change mysite.localhost
to erpnext-nginx
cp env-local .env
# change mysite.localhost to erpnext-nginx
sed -i -e "s/mysite.localhost/erpnext-nginx/g" .env
NOTE: recommended to use exact versions like (frappe v12.9.1 and
erpnext v12.11.2) instead of edge or v12 tag
- Add a file
sites/currentsite.txt
e.g. execute in container
echo erpnext-nginx > currentsite.txt
refer here
- This configuration sets default site for the deployment.
- traefik labels: these tell all the incoming requests to be reverse proxied to
erpnext-nginx
container and also sets the Host header to erpnext-nginx
.
erpnext-nginx
container gets host header as erpnext-nginx
irrespective of any site input in request and serves the site mentioned in currentsite.txt
, erpnext-nginx