diff --git a/templates/vhost.conf b/templates/vhost.conf
index aeeae55c22f50eb45702998c29ac8b95d6b054e5..3ef6dc30a661e50120c7eeccaf691a0465e3bb11 100644
--- a/templates/vhost.conf
+++ b/templates/vhost.conf
@@ -14,7 +14,7 @@
 {% if apache_version|default('2.4') == '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
+  LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
   ErrorLog {{ apacheLogDir }}/{{ matomo.domain }}-error.log
   CustomLog {{ apacheLogDir }}/{{ matomo.domain }}-access.log combined env=!forwarded
   CustomLog {{ apacheLogDir }}/{{ matomo.domain }}-access.log proxy env=forwarded
@@ -64,7 +64,7 @@
 {% if apache_version|default('2.4') == '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
+  LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
   ErrorLog {{ apacheLogDir }}/{{ matomo.domain }}-error.log
   CustomLog {{ apacheLogDir }}/{{ matomo.domain }}-access.log combined env=!forwarded
   CustomLog {{ apacheLogDir }}/{{ matomo.domain }}-access.log proxy env=forwarded
@@ -117,7 +117,7 @@
 {% if apache_version|default('2.4') == '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
+  LogFormat "\"%{X-Forwarded-For}i\" %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
   ErrorLog {{ apacheLogDir }}/{{ certs.domain }}-error.log
   CustomLog {{ apacheLogDir }}/{{ certs.domain }}-access.log combined env=!forwarded
   CustomLog {{ apacheLogDir }}/{{ certs.domain }}-access.log proxy env=forwarded