From bc430492c6ae2a098aec4805aef6111bc44347cd Mon Sep 17 00:00:00 2001 From: Sameer Naik Date: Tue, 26 Aug 2014 00:41:10 +0530 Subject: [PATCH] fix nginx static route handling when GITLAB_RELATIVE_URL_ROOT is used. nginx was not configured correctly to handle static routes due to which user uploaded files (in issues/wiki/avatar) were not being displayed. This issue was particularly visible when gitlab was configured to use a relative url root. This commit fixes the issue. --- Changelog.md | 1 + assets/config/nginx/gitlab | 4 ++-- assets/config/nginx/gitlab.https.permissive | 8 ++++---- assets/config/nginx/gitlab.https.strict | 4 ++-- assets/init | 1 + 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index 13c3437f..8a9de2f4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,6 +1,7 @@ # Changelog **latest** +- fix nginx static route handling when GITLAB_RELATIVE_URL_ROOT is used. - fix relative root access without the trailing '/' character - added seperate server block for http config in gitlab.https.permissive. Fixes #127 - added OAUTH_GOOGLE_RESTRICT_DOMAIN config option. diff --git a/assets/config/nginx/gitlab b/assets/config/nginx/gitlab index 569feb25..90f22c92 100644 --- a/assets/config/nginx/gitlab +++ b/assets/config/nginx/gitlab @@ -23,7 +23,7 @@ server { listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea server_name {{YOUR_SERVER_FQDN}}; # e.g., server_name source.example.com; server_tokens off; # don't show the version number, a security best practice - root /dev/null; + root {{GITLAB_INSTALL_DIR}}/public; # Increase this if you want to upload large attachments # Or if you want to accept large git objects over http @@ -34,7 +34,7 @@ server { error_log /var/log/nginx/gitlab_error.log; location {{GITLAB_RELATIVE_URL_ROOT}} { - root {{GITLAB_INSTALL_DIR}}/public; + # alias {{GITLAB_INSTALL_DIR}}/public; # serve static files from defined root folder;. # @gitlab is a named location for the upstream fallback, see below try_files $uri $uri/index.html $uri.html @gitlab; diff --git a/assets/config/nginx/gitlab.https.permissive b/assets/config/nginx/gitlab.https.permissive index c831ed6b..f54de154 100644 --- a/assets/config/nginx/gitlab.https.permissive +++ b/assets/config/nginx/gitlab.https.permissive @@ -63,7 +63,7 @@ server { listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea server_name {{YOUR_SERVER_FQDN}}; # e.g., server_name source.example.com; server_tokens off; # don't show the version number, a security best practice - root /dev/null; + root {{GITLAB_INSTALL_DIR}}/public; # Increase this if you want to upload large attachments # Or if you want to accept large git objects over http @@ -74,7 +74,7 @@ server { error_log /var/log/nginx/gitlab_error.log; location {{GITLAB_RELATIVE_URL_ROOT}} { - root {{GITLAB_INSTALL_DIR}}/public; + # alias {{GITLAB_INSTALL_DIR}}/public; # serve static files from defined root folder;. # @gitlab is a named location for the upstream fallback, see below try_files $uri $uri/index.html $uri.html @gitlab; @@ -116,7 +116,7 @@ server { ## Replace git.example.com with your FQDN. server_name {{YOUR_SERVER_FQDN}}; server_tokens off; - root /dev/null; + root {{GITLAB_INSTALL_DIR}}/public; ## Increase this if you want to upload large attachments ## Or if you want to accept large git objects over http @@ -159,7 +159,7 @@ server { error_log /var/log/nginx/gitlab_error.log; location {{GITLAB_RELATIVE_URL_ROOT}} { - root {{GITLAB_INSTALL_DIR}}/public; + # alias {{GITLAB_INSTALL_DIR}}/public; ## Serve static files from defined root folder. ## @gitlab is a named location for the upstream fallback, see below. try_files $uri $uri/index.html $uri.html @gitlab; diff --git a/assets/config/nginx/gitlab.https.strict b/assets/config/nginx/gitlab.https.strict index fcd7692c..f83057f2 100644 --- a/assets/config/nginx/gitlab.https.strict +++ b/assets/config/nginx/gitlab.https.strict @@ -76,7 +76,7 @@ server { ## Replace git.example.com with your FQDN. server_name {{YOUR_SERVER_FQDN}}; server_tokens off; - root /dev/null; + root {{GITLAB_INSTALL_DIR}}/public; ## Increase this if you want to upload large attachments ## Or if you want to accept large git objects over http @@ -119,7 +119,7 @@ server { error_log /var/log/nginx/gitlab_error.log; location {{GITLAB_RELATIVE_URL_ROOT}} { - root {{GITLAB_INSTALL_DIR}}/public; + # alias {{GITLAB_INSTALL_DIR}}/public; ## Serve static files from defined root folder. ## @gitlab is a named location for the upstream fallback, see below. try_files $uri $uri/index.html $uri.html @gitlab; diff --git a/assets/init b/assets/init index d536a7a4..366f3628 100755 --- a/assets/init +++ b/assets/init @@ -481,6 +481,7 @@ sudo -u git -H sed 's/{{OAUTH_BLOCK_AUTO_CREATED_USERS}}/'"${OAUTH_BLOCK_AUTO_CR if [ -n "${GITLAB_RELATIVE_URL_ROOT}" ]; then sed 's,{{GITLAB_RELATIVE_URL_ROOT}},'"${GITLAB_RELATIVE_URL_ROOT}"',g' -i /etc/nginx/sites-available/gitlab sed 's,{{GITLAB_RELATIVE_URL_ROOT__with_trailing_slash}},'"${GITLAB_RELATIVE_URL_ROOT}/"',g' -i /etc/nginx/sites-available/gitlab + sed 's,# alias '"${GITLAB_INSTALL_DIR}"'/public,alias '"${GITLAB_INSTALL_DIR}"'/public,g' -i /etc/nginx/sites-available/gitlab sudo -u git -H sed 's,# config.relative_url_root = "/gitlab",config.relative_url_root = "'${GITLAB_RELATIVE_URL_ROOT}'",' -i config/application.rb sudo -u git -H sed 's,# relative_url_root: {{GITLAB_RELATIVE_URL_ROOT}},relative_url_root: '${GITLAB_RELATIVE_URL_ROOT}',' -i config/gitlab.yml