Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.5\gitlab. This may not be ideal for a production env because it is not officially supported by GitLab, but it does seem to work.

share|improve this question

2 Answers 2

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

share|improve this answer
    
changed location /gitlab to location /gitlab/ and alias /home/git/gitlab/public; to alias /home/git/gitlab/public/; and I am still getting a 404 at http://192.168.1.5/gitlab and http://192.168.1.5/gitlab/ –  lee Sep 24 '13 at 1:20

for your question on alias: its a little "tricky"; from the docs

This directive assigns a path to be used as the basis for serving requests for the indicated location. Note that it may look similar to the root directive at first sight, but the document root doesn't change, just the file system path used for the request. The location part of the request is dropped in the request Nginx issues. Let's see this in action. Consider the following example.

location  /i/ {
  alias  /spool/w3/images/;
}

A request for "/i/top.gif" will instruct Nginx to serve the file "/spool/w3/images/top.gif". As you can see, only the part of the URI after the location is appended. The location itself, in this case "/i/", is dropped. With a root directive the full path is appended, i.e., in the above example it would have been, "/spool/w3/images/i/top.gif" — hence including also the location "/i/".

Aliases can also be used in a location specified by a regex.

For example:

location ~ ^/download/(.*)$ {
  alias /home/website/files/$1;
}

if you can, avoid alias and use root-directive, even in location-context.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.