GitLab alias for nginx

lee asked:

I have install GitLab 6.1 on a fresh Ubuntu 13.04 server, I would like have GitLab served up from a location like

http://192.168.1.5/gitlab

My /etc/nginx/sites-available/default file:

upstream gitlab {
    server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    server_name localhost 192.168.1.5;
    server_tokens off;

    location /gitlab {
        alias /home/git/gitlab/public;
        try_files $uri $uri/index.html $uri.html @gitlab;
    }

    location @gitlab {
        proxy_read_timeout 300; 
        proxy_connect_timeout 300; 
        proxy_redirect     off;

        proxy_set_header   X-Forwarded-Proto $scheme;
        proxy_set_header   Host              $http_host;
        proxy_set_header   X-Real-IP         $remote_addr;

        proxy_pass http://gitlab;
    }

    location / {
        try_files $uri $uri/ /index.html;
   }
}

I am new to nginx, but from what I understand the alias directive should be similar to alias in Apache. This configuration just 404s when navigating to

http://192.168.1.5/gitlab

If I change the /gitlab location to / and comment out the other / location, I can navigate to

http://192.168.1.5/ 

and access the GitLab instance.

Edit

It looks like GitLab does not officially sub directories, the devs suggest using sub domains instead. There is some unofficial support and documentation on sub directories. Following comments in GitLab config files and this thread (https://github.com/gitlabhq/gitlabhq/pull/4670) I was able to get it working:

1) Comment in config.relative_url_root = "/myproject" in config/application.rb

2) Update config.assets.version = '1.0.1' in config/application.rb

3) Comment in relative_url_root: /gitlab in config/gitlab.yml

4) Add ENV['RAILS_RELATIVE_URL_ROOT'] = "/gitlab" to the top of config/unicorn.rb

5) Run sudo -u git -H RAILS_ENV=production bundle exec rake assets:precompile

6) Run sudo service gitlab restart

7) Run sudo service nginx restart

Now the above nginx config serves up GitLab when navigating to http:\192.168.1.5gitlab. This may not be ideal for a production env because it is not officially supported by GitLab, but it does seem to work.

My answer:


When aliasing directories, make sure that the paths in both alias and its corresponding location have a trailing slash / character.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.