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.

Im having an issue trying to configure Nginx to work with gitlab and some other sites I have.

I have foo.com that points to my server. bar.foo.com also points to my server. I'm trying to have gitlab on bar.foo.com, and another website on foo.com

I thought I could easily do this using server blocks and server_names, but this doesnt appear to be correct.

What I tried doing is defining 3 different server blocks, with different server names. But this doesnt work. What happens is that when I try accessing foo.com I end up on bar.foo.com which is gitlab.

I keep just ending up on gitlab whatever I try doing. So I then thought maybe the root should go into the location folders, but that doesnt appear to change anything.

In my sites-enabled I currently have 3 files : gitlab, website1 and website2

Any help would be appreciated.

here is the gitlab configuration file

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

server {
  listen 80;         # e.g., listen 192.168.1.1:80;
  server_name bar.foo.com www.bar.foo.com;     # e.g., server_name source.example.com;
  #root /home/gitlab/gitlab/public;

  # individual nginx logs for this gitlab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  location / {
   root /home/gitlab/gitlab/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;
  }

  # if a file, which is not found in the root folder is requested,
  # then the proxy pass the request to the upsteam (gitlab unicorn)
  location @gitlab {
    root /home/gitlab/gitlab/public;
    proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
    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;
  }
}

Here is the second file :

 server { 
    listen 80;
    server_name foo.com www.foo.com;
    index index.html index.htm;
    #root /var/www/users;

    location / {
        root /var/www/users;
        try_files $uri $uri/ /index.html;
    } 
}

The third file is very similar to the second, so ill not bother posting it.

share|improve this question
    
Did you reload nginx and clear your browser cache? –  Michael Hampton Feb 13 '13 at 1:28
    
should be working that way...as you mentioned, server_name is the important directive and it looks good. –  MaddinXx Feb 13 '13 at 1:33
    
I restarted nginx. It should make the distinction between git.foo.com and foo.com shouldnt it ? Could it be because of the upstream ? –  squelos Feb 13 '13 at 3:34
add comment

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.