Skip to content

Commit 8f268a8

Browse files
committed
Disable rewrite ip for apache image
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent efe3cae commit 8f268a8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

.config/reverse_proxy.config.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$trustedProxies = getenv('TRUSTED_PROXIES');
4+
5+
if ($trustedProxies) {
6+
$trustedProxies = array_filter(array_map('trim', explode(' ', $trustedProxies)));
7+
} else {
8+
$trustedProxies = null;
9+
}
10+
11+
$CONFIG['trusted_proxies'] = $trustedProxies;

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ To use an external SMTP server, you have to provide the connection details. To c
158158

159159
Check the [Nextcloud documentation](https://docs.nextcloud.com/server/15/admin_manual/configuration_server/email_configuration.html) for other values to configure SMTP.
160160

161+
## Using the apache image behind a reverse proxy and auto configure server host and protocol
162+
163+
The apache image will replace the remote addr (ip address visible to Nextcloud) with the ip address from `X-Real-IP` if the request is coming from a proxy in 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16 by default. If you want Nextcloud to pick up the server host (`HTTP_X_FORWARDED_HOST`), protocol (`HTTP_X_FORWARDED_PROTO`) and client ip (`HTTP_X_FORWARDED_FOR`) from a trusted proxy disable rewrite ip and the reverse proxies ip address to `TRUSTED_PROXIES`.
164+
165+
- `APACHE_DISABLE_REWRITE_IP` (not set by default): Set to 1 to disable rewrite ip.
166+
167+
- `TRUSTED_PROXIES` (empty by default): A space-separated list of trusted proxies. CIDR notation is supported for IPv4.
168+
161169
# Running this image with docker-compose
162170
The easiest way to get a fully featured and functional setup is using a `docker-compose` file. There are too many different possibilities to setup your system, so here are only some examples of what you have to look for.
163171

docker-entrypoint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ file_env() {
4343
unset "$fileVar"
4444
}
4545

46+
if expr "$1" : "apache" 1>/dev/null; then
47+
if [ -n "${APACHE_DISABLE_REWRITE_IP+x}" ]; then
48+
a2disconf remoteip
49+
fi
50+
fi
51+
4652
if expr "$1" : "apache" 1>/dev/null || [ "$1" = "php-fpm" ] || [ "${NEXTCLOUD_UPDATE:-0}" -eq 1 ]; then
4753
if [ -n "${REDIS_HOST+x}" ]; then
4854

0 commit comments

Comments
 (0)