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
12 changes: 12 additions & 0 deletions docs/develop/update/apache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ The service should now be available at its ``https://`` web address.

curl https://SERVERNAME/.httpd/certificate-status

Split site logs
---------------

Add to your server's Pillar file:

.. code-block:: yaml

apache:
site_logs: True

This will configure sites to use their own log file in ``/var/log/apache2/{site}/access.log``.

.. _apache-modules:

Enable Apache modules
Expand Down
1 change: 1 addition & 0 deletions pillar/cms.sls
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ backup:
# Sites are configured in each CMS' Pillar file.
apache:
public_access: True
site_logs: True

# Databases and users are configured in each CMS' Pillar file.
mysql:
Expand Down
6 changes: 6 additions & 0 deletions salt/apache/files/sites/_common.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
{#- https://github.com/icing/mod_md#tls-alpn-challenges #}
Protocols h2 http/1.1 acme-tls/1

{#- System-wide configuration files should be prefixed with numbers #}
{%- if pillar.apache.get('site_logs') and not filename[:1].isdigit() %}
ErrorLog /var/log/apache2/{{ filename }}/error.log
CustomLog /var/log/apache2/{{ filename }}/access.log vhost_combined
{%- endif %}

Include {{ includefile }}
{%- elif not servername %}

Expand Down
8 changes: 6 additions & 2 deletions salt/apache/init.sls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% from 'lib.sls' import apache, set_firewall, unset_firewall %}
{% from 'lib.sls' import apache, logrotate, set_firewall, unset_firewall %}

{% if salt['pillar.get']('apache:public_access') %}
{{ set_firewall('PUBLIC_HTTP') }}
Expand Down Expand Up @@ -63,7 +63,7 @@ apache2-utils:

# Ensure this configuration is loaded first.
{{ apache('00-default', {'configuration': 'default', 'servername': ''}) }}
{{ apache('fqdn', {'configuration': 'default', 'servername': grains.fqdn}) }}
{{ apache('10-fqdn', {'configuration': 'default', 'servername': grains.fqdn}) }}

{% if salt['pillar.get']('apache:modules:mod_autoindex:enabled') %}
autoindex:
Expand Down Expand Up @@ -143,3 +143,7 @@ disable-conf-other-vhosts-access-log.conf:
- onchanges:
- file: /etc/systemd/system/apache2.service.d/customization.conf
{% endif %}

{% if pillar.apache.get('site_logs') %}
{{ logrotate('apache-site-logs') }}
{% endif %}
10 changes: 10 additions & 0 deletions salt/core/fail2ban/files/jail.local
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ logpath = /var/log/apache2/access.log
maxretry = 10
findtime = 1m
bantime = 1h

{% if pillar.apache.get('site_logs') %}
[apache-custom-site-logs]
enabled = true
filter = apache-auth
port = http,https
logpath = /var/log/apache2/*/*.log
maxretry = 10
findtime = 1m
{%- endif %}
{%- endif %}
{%- if salt['pillar.get']('postgres:public_access') %}

Expand Down
20 changes: 20 additions & 0 deletions salt/core/logrotate/files/apache-site-logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/var/log/apache2/*/*.log {
rotate 14
daily
missingok
notifempty
compress
delaycompress
sharedscripts
create 644 root adm
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then
run-parts /etc/logrotate.d/httpd-prerotate
fi
endscript
postrotate
if pgrep -f ^/usr/sbin/apache2 > /dev/null; then
invoke-rc.d apache2 reload 2>&1 | logger -t apache2.logrotate
fi
endscript
}
10 changes: 3 additions & 7 deletions salt/core/logrotate/init.sls
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
{% from 'lib.sls' import logrotate %}

# Some configurations use `postrotate /usr/lib/rsyslog/rsyslog-rotate`, so rsyslog is required.
include:
- core.rsyslog

{% for filename, entry in salt['pillar.get']('logrotate:conf', {})|items %}
/etc/logrotate.d/{{ filename }}:
file.managed:
- source: salt://core/logrotate/files/{{ entry.source }}
{% if 'context' in entry %}
- template: jinja
- context: {{ entry.context|yaml }}
{% endif %}
{{ logrotate(filename, entry) }}
{% endfor %}
21 changes: 21 additions & 0 deletions salt/lib.sls
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ unset {{ setting_name }} in {{ filename }}:
servername: {{ entry.servername }}
serveraliases: {{ entry.serveraliases|default([])|yaml }}
https: {{ entry.https|default(true) }}
filename: {{ name }}
- require:
- file: /etc/apache2/sites-available/{{ name }}.conf.include
- watch_in:
Expand All @@ -190,6 +191,16 @@ add .htpasswd-{{ name }}-{{ username }}:
- require:
- pkg: apache2
{% endfor %}

{% if pillar.apache.get('site_logs') and not name[:1].isdigit() %}
/var/log/apache2/{{ name }}:
file.directory:
- user: root
- group: adm
- dir_mode: 755
- require_in:
- file: /etc/apache2/sites-available/{{ name }}.conf
{% endif%}
{% endmacro %}

{#
Expand Down Expand Up @@ -242,3 +253,13 @@ add .htpasswd-{{ name }}-{{ username }}:
- watch_in:
- module: nginx-reload
{% endmacro %}

{% macro logrotate(name, entry={}) %}
/etc/logrotate.d/{{ name }}:
file.managed:
- source: salt://core/logrotate/files/{{ entry.source|default(name) }}
{% if 'context' in entry %}
- template: jinja
- context: {{ entry.context|yaml }}
{% endif %}
{% endmacro %}