diff --git a/templates/gitlab.rb.j2 b/templates/gitlab.rb.j2
index a40dc8ba5934023579c9bdaf3af998c2e790a754..39e642bfeee606d1236bd4abc9085a0ac3b96e89 100644
--- a/templates/gitlab.rb.j2
+++ b/templates/gitlab.rb.j2
@@ -1403,10 +1403,17 @@ pages_external_url "{{ gitlab.pages_external_url }}"
 gitlab_pages['enable'] = true
 
 ##! Configure to expose GitLab Pages on external IP address, serving the HTTP
+{% if gitlab.pages_listen %}
 gitlab_pages['external_http'] = {{ gitlab.pages_listen|to_json }}
+{% endif %}
 
 ##! Configure to expose GitLab Pages on external IP address, serving the HTTPS
+{% if gitlab.pages_listen_ssl %}
 gitlab_pages['external_https'] = {{ gitlab.pages_listen_ssl|to_json }}
+{% endif %}
+
+##! Listen for requests forwarded by reverse proxy
+gitlab_pages['listen_proxy'] = '{{ gitlab.pages_listen_proxy }}'
 
 ##! Configure to use the default list of cipher suites
 # gitlab_pages['insecure_ciphers'] = false
@@ -1429,9 +1436,6 @@ gitlab_pages['external_https'] = {{ gitlab.pages_listen_ssl|to_json }}
 # gitlab_pages['sentry_dsn'] = 'https://<key>@sentry.io/<project>'
 # gitlab_pages['sentry_environment'] = 'production'
 
-##! Listen for requests forwarded by reverse proxy
-gitlab_pages['listen_proxy'] = '{{ gitlab.pages_listen_proxy }}'
-
 ##! Configure GitLab Pages to use an HTTP Proxy
 # gitlab_pages['http_proxy'] = "http://example:8080"
 
@@ -1473,7 +1477,9 @@ gitlab_pages['access_control'] = true
 # gitlab_pages['gitlab_client_jwt_expiry'] = "30s"
 
 ##! Define custom gitlab-pages HTTP headers for the whole instance
+{% if gitlab.pages_headers %}
 gitlab_pages['headers'] = {{ gitlab.pages_headers|to_json }}
+{% endif %}
 
 ##! Shared secret used for authentication between Pages and GitLab
 # gitlab_pages['api_secret_key'] = nil # Will be generated if not set. Base64 encoded and exactly 32 bytes long.