diff --git a/README.md b/README.md index e1152f5e1..a820f261d 100644 --- a/README.md +++ b/README.md @@ -1868,11 +1868,11 @@ Sets the bucket size for the server names hash tables. This is needed when you h ##### `NGINX_HSTS_ENABLED` -Advanced configuration option for turning off the HSTS configuration. Applicable only when SSL is in use. Defaults to `true`. See [#138](https://github.com/sameersbn/docker-gitlab/issues/138) for use case scenario. +Advanced configuration option for turning off HSTS for the GitLab and GitLab Pages nginx virtual hosts. Applicable only when SSL is in use. Defaults to `true`. See [#138](https://github.com/sameersbn/docker-gitlab/issues/138) for use case scenario. ##### `NGINX_HSTS_MAXAGE` -Advanced configuration option for setting the HSTS max-age in the gitlab nginx vHost configuration. Applicable only when SSL is in use. Defaults to `31536000`. +Advanced configuration option for setting the HSTS max-age in the GitLab and GitLab Pages nginx virtual hosts. Applicable only when SSL is in use. Defaults to `31536000`. ##### `NGINX_PROXY_BUFFERING` diff --git a/assets/runtime/config/nginx/gitlab-pages b/assets/runtime/config/nginx/gitlab-pages index c9f006c3b..65fece634 100644 --- a/assets/runtime/config/nginx/gitlab-pages +++ b/assets/runtime/config/nginx/gitlab-pages @@ -9,6 +9,7 @@ server { ## Individual nginx logs for GitLab pages access_log {{GITLAB_LOG_DIR}}/nginx/gitlab_pages_access.log; error_log {{GITLAB_LOG_DIR}}/nginx/gitlab_pages_error.log; + add_header Strict-Transport-Security "max-age={{NGINX_HSTS_MAXAGE}}"; location / { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; diff --git a/assets/runtime/config/nginx/gitlab-pages-ssl b/assets/runtime/config/nginx/gitlab-pages-ssl index 8563c1a92..512bb7dff 100644 --- a/assets/runtime/config/nginx/gitlab-pages-ssl +++ b/assets/runtime/config/nginx/gitlab-pages-ssl @@ -30,6 +30,8 @@ server { server_name ~^.*{{GITLAB_PAGES_DOMAIN}}; server_tokens off; ## Don't show the nginx version number, a security best practice + add_header Strict-Transport-Security "max-age={{NGINX_HSTS_MAXAGE}}"; + ## Strong SSL Security ## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html & https://cipherli.st/ ssl_certificate {{SSL_PAGES_CERT_PATH}}; diff --git a/assets/runtime/functions b/assets/runtime/functions index fe42f3276..1dfd5c1c3 100644 --- a/assets/runtime/functions +++ b/assets/runtime/functions @@ -1656,6 +1656,9 @@ nginx_configure_pages(){ if [[ ${GITLAB_PAGES_ENABLED} == true ]]; then echo "Configuring nginx::gitlab-pages..." if [[ ${GITLAB_PAGES_NGINX_PROXY} == true ]]; then + if [[ ${GITLAB_PAGES_HTTPS} != true || ${NGINX_HSTS_ENABLED} != true ]]; then + sed -i "/{{NGINX_HSTS_MAXAGE}}/d" ${GITLAB_PAGES_NGINX_CONFIG} + fi if [[ ${GITLAB_PAGES_HTTPS} == true ]]; then update_template ${GITLAB_PAGES_NGINX_CONFIG} \ GITLAB_PORT \ @@ -1668,6 +1671,7 @@ nginx_configure_pages(){ SSL_PAGES_CIPHERS \ SSL_PAGES_PROTOCOLS \ SSL_DHPARAM_PATH \ + NGINX_HSTS_MAXAGE \ GITLAB_LOG_DIR else update_template ${GITLAB_PAGES_NGINX_CONFIG} \