Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions salt/apache/cloudflare.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/
include:
- apache
- apache.modules.remoteip

/etc/apache2/conf-available/zz-cloudflare-proxy.conf:
file.managed:
- contents: |
RemoteIPHeader CF-Connecting-IP
{%- for ip in salt.cmd.run('curl -sS https://www.cloudflare.com/ips-v4/').split() %}
RemoteIPTrustedProxy {{ ip }}
{%- endfor %}
{%- for ip in salt.cmd.run('curl -sS https://www.cloudflare.com/ips-v6/').split() %}
RemoteIPTrustedProxy {{ ip }}
{%- endfor %}
- require:
- pkg: apache2
- watch_in:
- module: apache2-reload

enable-conf-zz-cloudflare-proxy.conf:
apache_conf.enabled:
- name: zz-cloudflare-proxy
- require:
- file: /etc/apache2/conf-available/zz-cloudflare-proxy.conf
- watch_in:
- module: apache2-reload
3 changes: 3 additions & 0 deletions salt/apache/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ disable site 000-default.conf:
#
# - Do not disclose the Apache version, to avoid false positives about CVE patching.
# - Do not log uptime monitoring remote requests and Netdata's mod_status requests, to reduce log noise.
# - Restore original visitor IPs in logs when using a proxy. (%a behaves like the default %h if mod_remoteip isn't configured.)
#
# https://httpd.apache.org/docs/2.4/logs.html#conditional
/etc/apache2/conf-available/zz-customization.conf:
Expand All @@ -102,6 +103,8 @@ disable site 000-default.conf:
SetEnvIf User-Agent AppBeat dontlog
SetEnvIf User-Agent Pingdom.com_bot dontlog
SetEnvIf Request_URI "^/server-status$" dontlog
LogFormat "%v:%p %a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined env=!dontlog
{{ salt['pillar.get']('apache:customization','') | indent(8) }}
- require:
Expand Down
2 changes: 2 additions & 0 deletions salt/top.sls
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ base:
- apache.modules.headers
# Enable HTTPS redirects on the default site.
- apache.modules.rewrite
# Restore original visitor IPs in logs.
- apache.cloudflare

# All public web servers should use SSL certificates.
'I@nginx:public_access:true':
Expand Down