Sign up ×
Server Fault is a question and answer site for 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 that points to my server. also points to my server. I'm trying to have gitlab on, and another website on

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 I end up on 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;
  server_name;     # e.g., server_name;
  #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; #
    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;

Here is the second file :

 server { 
    listen 80;
    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 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 and shouldnt it ? Could it be because of the upstream ? – squelos Feb 13 '13 at 3:34

Your Answer


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

Browse other questions tagged or ask your own question.