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.
This commit is contained in:
Sameer Naik 2014-08-26 00:41:10 +05:30
parent 421018d563
commit bc430492c6
5 changed files with 10 additions and 8 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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