diff --git a/templates/default b/templates/default
index 91865a3409bded46cf56322668006642e4c6282f..3f1265323bde36a9025c70184daf371ac340c10e 100644
--- a/templates/default
+++ b/templates/default
@@ -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 ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
   CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded
diff --git a/templates/default-ssl b/templates/default-ssl
index 278dce57e7b0a1690fa3b04f704920b9814e72dd..c4f07eda5d89d5f943608109af55499adbf8613c 100644
--- a/templates/default-ssl
+++ b/templates/default-ssl
@@ -62,7 +62,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 ${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
@@ -122,7 +122,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 ${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