diff --git a/templates/default b/templates/default
index 5eac57801dab83a6e4487912b21f3b66472d66ab..a77f7bc489ce39651e9d1241f39864ee7a051ae5 100644
--- a/templates/default
+++ b/templates/default
@@ -9,9 +9,15 @@
     Options -MultiViews
   </Directory>
 
-  ErrorLog /var/log/apache2/error.log
+  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
   LogLevel warn
-  CustomLog /var/log/apache2/access.log combined
+{% if apache_version == '2.4' %}
+  ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
+{% endif %}
+  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
+  ErrorLog ${APACHE_LOG_DIR}/error.log
+  CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
+  CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded
 </VirtualHost>
 
 <VirtualHost *:80>
diff --git a/templates/default-ssl b/templates/default-ssl
index 759e84307e79fa955ef21848c83731e53aa99967..20ba9abd24b2bd74aecfee7805d8de2547a4caf8 100644
--- a/templates/default-ssl
+++ b/templates/default-ssl
@@ -57,14 +57,15 @@
   ErrorDocument 500 /500.html
   ErrorDocument 503 /deploy.html
 
-  # It is assumed that the log directory is in /var/log/httpd.
-  # For Debian distributions you might want to change this to
-  # /var/log/apache2.
-  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
-  ErrorLog ${APACHE_LOG_DIR}/gitlab_ssl_error.log
-  CustomLog ${APACHE_LOG_DIR}/gitlab_ssl_forwarded.log common_forwarded
-  CustomLog ${APACHE_LOG_DIR}/gitlab_ssl_access.log combined env=!dontlog
-  CustomLog ${APACHE_LOG_DIR}/gitlab_ssl.log combined
+  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
+  LogLevel warn
+{% if apache_version == '2.4' %}
+  ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
+{% endif %}
+  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
+  ErrorLog ${APACHE_LOG_DIR}/gitlab-error.log
+  CustomLog ${APACHE_LOG_DIR}/gitlab-access.log combined env=!forwarded
+  CustomLog ${APACHE_LOG_DIR}/gitlab-access.log proxy env=forwarded
 </VirtualHost>
 
 <VirtualHost _default_:443>
@@ -116,9 +117,13 @@
     ProxyPassReverseCookieDomain 127.0.0.1 {{ mattermost_domain }}
   </Location>
 
-  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
-  ErrorLog /var/log/apache2/mattermost_error.log
-  CustomLog /var/log/apache2/mattermost_forwarded.log common_forwarded
-  CustomLog /var/log/apache2/mattermost_access.log combined env=!dontlog
-  CustomLog /var/log/apache2/mattermost.log combined
+  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
+  LogLevel warn
+{% if apache_version == '2.4' %}
+  ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
+{% endif %}
+  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
+  ErrorLog ${APACHE_LOG_DIR}/mattermost-error.log
+  CustomLog ${APACHE_LOG_DIR}/mattermost-access.log combined env=!forwarded
+  CustomLog ${APACHE_LOG_DIR}/mattermost-access.log proxy env=forwarded
 </VirtualHost>