Merge pull request #1994 from sujaldev/feature/nginx-listen-port
feat: make the internal nginx server's listen port configurable
This commit is contained in:
commit
51a27404fa
|
|
@ -59,6 +59,7 @@ services:
|
||||||
environment:
|
environment:
|
||||||
BACKEND: backend:8000
|
BACKEND: backend:8000
|
||||||
SOCKETIO: websocket:9000
|
SOCKETIO: websocket:9000
|
||||||
|
NGINX_LISTEN_PORT: ${NGINX_LISTEN_PORT:-8080}
|
||||||
FRAPPE_SITE_NAME_HEADER: ${FRAPPE_SITE_NAME_HEADER:-$$host}
|
FRAPPE_SITE_NAME_HEADER: ${FRAPPE_SITE_NAME_HEADER:-$$host}
|
||||||
UPSTREAM_REAL_IP_ADDRESS: ${UPSTREAM_REAL_IP_ADDRESS:-127.0.0.1}
|
UPSTREAM_REAL_IP_ADDRESS: ${UPSTREAM_REAL_IP_ADDRESS:-127.0.0.1}
|
||||||
UPSTREAM_REAL_IP_HEADER: ${UPSTREAM_REAL_IP_HEADER:-X-Forwarded-For}
|
UPSTREAM_REAL_IP_HEADER: ${UPSTREAM_REAL_IP_HEADER:-X-Forwarded-For}
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ If your site is named `example.com` and you access it via that domain, no need t
|
||||||
|
|
||||||
| Variable | Purpose | Default | Allowed Values |
|
| Variable | Purpose | Default | Allowed Values |
|
||||||
| ---------------------- | ---------------------------------- | -------------- | -------------------------------------------- |
|
| ---------------------- | ---------------------------------- | -------------- | -------------------------------------------- |
|
||||||
|
| `NGINX_LISTEN_PORT` | Sets the `listen` directive | `8080` | `{port}` |
|
||||||
| `BACKEND` | Backend service address and port | `0.0.0.0:8000` | `{host}:{port}` |
|
| `BACKEND` | Backend service address and port | `0.0.0.0:8000` | `{host}:{port}` |
|
||||||
| `SOCKETIO` | Socket.IO service address and port | `0.0.0.0:9000` | `{host}:{port}` |
|
| `SOCKETIO` | Socket.IO service address and port | `0.0.0.0:9000` | `{host}:{port}` |
|
||||||
| `PROXY_READ_TIMEOUT` | Upstream request timeout | `120s` | Any nginx timeout value (e.g., `300s`, `5m`) |
|
| `PROXY_READ_TIMEOUT` | Upstream request timeout | `120s` | Any nginx timeout value (e.g., `300s`, `5m`) |
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
---
|
||||||
|
title: Advanced Setups
|
||||||
|
---
|
||||||
|
|
||||||
|
# Introduction
|
||||||
|
|
||||||
|
This document describes some advanced setups that may add additional features, performance improvements, or security
|
||||||
|
properties that are not present in the default setup. It is beyond the scope of this project to provide support for any
|
||||||
|
of these setups, and users are advised to ensure they fully understand the implications of using the following
|
||||||
|
suggestions in their deployment.
|
||||||
|
|
||||||
|
## Using Unix Sockets
|
||||||
|
|
||||||
|
A [Unix domain socket](https://wikipedia.org/wiki/Unix_domain_socket) can be used as the transport between your public
|
||||||
|
proxy and the frontend container. This can provide the following benefits:
|
||||||
|
|
||||||
|
1. The socket file can be configured with standard Unix file permissions, and additional ACL rules.
|
||||||
|
2. SELinux can be used to further restrict access to the socket file with custom policies.
|
||||||
|
3. Unix sockets have slightly lower overhead than a local TCP connection.
|
||||||
|
|
||||||
|
The value of the [`NGINX_LISTEN_PORT`](../02-setup/04-env-variables.md#frontend-nginx-configuration-inside-the-frontend-container)
|
||||||
|
environment variable is directly substituted into the internal Nginx server's [listen](https://nginx.org/en/docs/http/ngx_http_core_module.html#listen)
|
||||||
|
directive, which allows passing a `unix:/path/to/socket` value instead of a port value. Note that this may break some
|
||||||
|
compose overrides that strictly expect a port value here.
|
||||||
|
|
||||||
|
This can be combined with [systemd socket activation](https://www.freedesktop.org/software/systemd/man/latest/systemd.socket.html)
|
||||||
|
and [Podman Quadlets](https://docs.podman.io/en/latest/markdown/podman-systemd.unit.5.html). Refer to this [guide](https://github.com/eriksjolund/podman-nginx-socket-activation)
|
||||||
|
by Erik Sjölund to see how Nginx can be made to work with socket activation. Note that Nginx does not officially support
|
||||||
|
socket activation, and this setup relies on undocumented functionality in Nginx.
|
||||||
|
|
@ -49,6 +49,10 @@ HTTP_PUBLISH_PORT=
|
||||||
# Default value is `443`.
|
# Default value is `443`.
|
||||||
HTTPS_PUBLISH_PORT=
|
HTTPS_PUBLISH_PORT=
|
||||||
|
|
||||||
|
# Port on which the internal nginx server listens.
|
||||||
|
# Default value is `8080`.
|
||||||
|
NGINX_LISTEN_PORT=
|
||||||
|
|
||||||
# Default value is `127.0.0.1`. Set IP address as our trusted upstream address.
|
# Default value is `127.0.0.1`. Set IP address as our trusted upstream address.
|
||||||
UPSTREAM_REAL_IP_ADDRESS=
|
UPSTREAM_REAL_IP_ADDRESS=
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ services:
|
||||||
- caddy
|
- caddy
|
||||||
- reverse-proxy
|
- reverse-proxy
|
||||||
- --to
|
- --to
|
||||||
- frontend:8080
|
- frontend:${NGINX_LISTEN_PORT:-8080}
|
||||||
- --from
|
- --from
|
||||||
- :2016
|
- :2016
|
||||||
labels:
|
labels:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ services:
|
||||||
frontend:
|
frontend:
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.http.services.frontend.loadbalancer.server.port=8080
|
- traefik.http.services.frontend.loadbalancer.server.port=${NGINX_LISTEN_PORT:-8080}
|
||||||
- traefik.http.routers.frontend-http.entrypoints=websecure
|
- traefik.http.routers.frontend-http.entrypoints=websecure
|
||||||
- traefik.http.routers.frontend-http.tls.certresolver=main-resolver
|
- traefik.http.routers.frontend-http.tls.certresolver=main-resolver
|
||||||
- traefik.http.routers.frontend-http.rule=${SITES_RULE:?SITES_RULE not set}
|
- traefik.http.routers.frontend-http.rule=${SITES_RULE:?SITES_RULE not set}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ services:
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.docker.network=traefik-public
|
- traefik.docker.network=traefik-public
|
||||||
- traefik.http.services.${ROUTER?ROUTER not set}.loadbalancer.server.port=8080
|
- traefik.http.services.${ROUTER?ROUTER not set}.loadbalancer.server.port=${NGINX_LISTEN_PORT:-8080}
|
||||||
- traefik.http.routers.${ROUTER}-http.service=${ROUTER}
|
- traefik.http.routers.${ROUTER}-http.service=${ROUTER}
|
||||||
- traefik.http.routers.${ROUTER}-http.entrypoints=http
|
- traefik.http.routers.${ROUTER}-http.entrypoints=http
|
||||||
- traefik.http.routers.${ROUTER}-http.rule=${SITES_RULE?SITES_RULE not set}
|
- traefik.http.routers.${ROUTER}-http.rule=${SITES_RULE?SITES_RULE not set}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ services:
|
||||||
frontend:
|
frontend:
|
||||||
environment:
|
environment:
|
||||||
VIRTUAL_HOST: ${NGINX_PROXY_HOSTS:?No NGINX_PROXY_HOSTS set}
|
VIRTUAL_HOST: ${NGINX_PROXY_HOSTS:?No NGINX_PROXY_HOSTS set}
|
||||||
VIRTUAL_PORT: 8080
|
VIRTUAL_PORT: ${NGINX_LISTEN_PORT:-8080}
|
||||||
|
|
||||||
nginx-proxy:
|
nginx-proxy:
|
||||||
image: nginxproxy/nginx-proxy:1.11.6-alpine
|
image: nginxproxy/nginx-proxy:1.11.6-alpine
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
services:
|
services:
|
||||||
frontend:
|
frontend:
|
||||||
ports:
|
ports:
|
||||||
- ${HTTP_PUBLISH_PORT:-8080}:8080
|
- ${HTTP_PUBLISH_PORT:-8080}:${NGINX_LISTEN_PORT:-8080}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ services:
|
||||||
frontend:
|
frontend:
|
||||||
labels:
|
labels:
|
||||||
- traefik.enable=true
|
- traefik.enable=true
|
||||||
- traefik.http.services.frontend.loadbalancer.server.port=8080
|
- traefik.http.services.frontend.loadbalancer.server.port=${NGINX_LISTEN_PORT:-8080}
|
||||||
- traefik.http.routers.frontend-http.entrypoints=web
|
- traefik.http.routers.frontend-http.entrypoints=web
|
||||||
- traefik.http.routers.frontend-http.rule=HostRegexp(`^.+$`)
|
- traefik.http.routers.frontend-http.rule=HostRegexp(`^.+$`)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ services:
|
||||||
# Enable HTTP Basic auth, using the middleware created above
|
# Enable HTTP Basic auth, using the middleware created above
|
||||||
- traefik.http.routers.traefik-public-http.middlewares=admin-auth
|
- traefik.http.routers.traefik-public-http.middlewares=admin-auth
|
||||||
# Define the port inside of the Docker service to use
|
# Define the port inside of the Docker service to use
|
||||||
- traefik.http.services.traefik-public.loadbalancer.server.port=8080
|
- traefik.http.services.traefik-public.loadbalancer.server.port=${NGINX_LISTEN_PORT:-8080}
|
||||||
command:
|
command:
|
||||||
# Enable Docker in Traefik, so that it reads labels from Docker services
|
# Enable Docker in Traefik, so that it reads labels from Docker services
|
||||||
- --providers.docker=true
|
- --providers.docker=true
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,10 @@ if [[ -z "$SOCKETIO" ]]; then
|
||||||
echo "SOCKETIO defaulting to 0.0.0.0:9000"
|
echo "SOCKETIO defaulting to 0.0.0.0:9000"
|
||||||
export SOCKETIO=0.0.0.0:9000
|
export SOCKETIO=0.0.0.0:9000
|
||||||
fi
|
fi
|
||||||
|
if [[ -z "$NGINX_LISTEN_PORT" ]]; then
|
||||||
|
echo "NGINX_LISTEN_PORT defaulting to 8080"
|
||||||
|
export NGINX_LISTEN_PORT=8080
|
||||||
|
fi
|
||||||
if [[ -z "$UPSTREAM_REAL_IP_ADDRESS" ]]; then
|
if [[ -z "$UPSTREAM_REAL_IP_ADDRESS" ]]; then
|
||||||
echo "UPSTREAM_REAL_IP_ADDRESS defaulting to 127.0.0.1"
|
echo "UPSTREAM_REAL_IP_ADDRESS defaulting to 127.0.0.1"
|
||||||
export UPSTREAM_REAL_IP_ADDRESS=127.0.0.1
|
export UPSTREAM_REAL_IP_ADDRESS=127.0.0.1
|
||||||
|
|
@ -41,6 +45,7 @@ fi
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
envsubst '${BACKEND}
|
envsubst '${BACKEND}
|
||||||
${SOCKETIO}
|
${SOCKETIO}
|
||||||
|
${NGINX_LISTEN_PORT}
|
||||||
${UPSTREAM_REAL_IP_ADDRESS}
|
${UPSTREAM_REAL_IP_ADDRESS}
|
||||||
${UPSTREAM_REAL_IP_HEADER}
|
${UPSTREAM_REAL_IP_HEADER}
|
||||||
${UPSTREAM_REAL_IP_RECURSIVE}
|
${UPSTREAM_REAL_IP_RECURSIVE}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ map $http_x_forwarded_proto $proxy_x_forwarded_proto {
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 8080;
|
listen ${NGINX_LISTEN_PORT};
|
||||||
server_name ${FRAPPE_SITE_NAME_HEADER};
|
server_name ${FRAPPE_SITE_NAME_HEADER};
|
||||||
absolute_redirect off;
|
absolute_redirect off;
|
||||||
root /home/frappe/frappe-bench/sites;
|
root /home/frappe/frappe-bench/sites;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue