1

I'm trying to set up a website (website.com) on an Ubuntu 14.04 machine.

When '/etc/nginx/sites-available/wordpress' is present, I can run the gitlab server on website.com/gitlab (as intended)

When '/etc/nginx/sites-available/gitlab' is present, I can run the wordpress server on website.com (as intended)

when both 'wordpress' and 'gitlab' are in 'sites-available', website.com/gitlab is accessible, but website.com return a 403, forbidden error.

How can I make both wordpress and gitlab work together?

Thanks!

configuration files on /etc/nginx/sites-available

gitlab

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

## Normal HTTP host
server {
  listen 0.0.0.0:80;
  listen [::]:80;
  server_name localhost ztomer.ax.lt; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /home/git/gitlab/public;

  client_max_body_size 20m;

  ## See app/controllers/application_controller.rb for headers set

  ## Individual nginx logs for this GitLab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

  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    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;

    proxy_pass http://gitlab;
  }

  location ~ ^/(assets)/ {
    root /home/git/gitlab/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  error_page 502 /502.html;
}

wordpress

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

    root /var/www/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost ztomer.ax.lt;

    location = / {
        try_files /nonexistent /index.php?q=$uri&$args;
    }

# magically link wordpress here
    location / {        
        try_files $uri $uri/ $uri/index.html /index.php?q=$uri&$args;
    }
    error_page 404 /404.html;

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;

        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

}

}

4
  • 2
    The server_name directive is being used in more than one server block for the same domain. You need to have all of your configurations for ztomer.ax.lt in the same server block.
    – Paul
    Dec 19, 2014 at 0:06
  • I've moved the location / {} block to gitlab, under the server {} block. I still get the same '403 forbidden' error. Is there something else I need to do? Dec 19, 2014 at 7:11
  • I am assuming you are checking your error logs and have run nginx -t with root user privileges?
    – Paul
    Dec 19, 2014 at 17:43
  • 1
    yep: [ OK ] $ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful Dec 19, 2014 at 17:46

2 Answers 2

2

You need to update the root directive in the configuration, assuming that your WordPress resides under /var/www/html and not /home/git/gitlab/public.

1
  • I've tried updating the root directive, still getting '403 forbidden' error (update #2). Dec 19, 2014 at 17:43
2

Success!! Steps to correct:

  1. Used a single site file
  2. Added explicit root directive to each location block
  3. Order of parsing is important, I've put the location / {} block first
  4. added an index directive to location / {} block.

Thanks for your help guys!

working configuration file:

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

## Normal HTTP host
server {
  listen 0.0.0.0:80;
  listen [::]:80;
  server_name localhost ztomer.ax.lt; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  # root /home/git/gitlab/public;

  ## Increase this if you want to upload large attachments
  ## Or if you want to accept large git objects over http
  client_max_body_size 1024m;

  ## See app/controllers/application_controller.rb for headers set

  ## Individual nginx logs for this GitLab vhost
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;

 # magically link wordpress here
   location / {
       root /var/www/html;
       index index.php;
       try_files $uri $uri/ $uri/index.html /index.php?q=$uri&$args;
   }
   error_page 404 /404.html;

   error_page 500 502 503 504 /50x.html;
   location = /50x.html {
        root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
   location ~ \.php$ {
       root /var/www/html;
       try_files $uri =404;
       fastcgi_split_path_info ^(.+\.php)(/.+)$;

       fastcgi_pass unix:/var/run/php5-fpm.sock;
       fastcgi_index index.php;
       include fastcgi_params;
   }

  location ~* /gitlab {
    root /home/git/gitlab/public;
    ## Serve static files from defined root folder.
    ## @gitlab is a named location for the upstream fallback, see below.
    # alias /home/git/gitlab/public;
    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 passes the request to the upsteam (gitlab unicorn).
  location @gitlab {
    root /home/git/gitlab/public;
    ## If you use HTTPS make sure you disable gzip compression
    ## to be safe against BREACH attack.
    # gzip off;

    ## https://github.com/gitlabhq/gitlabhq/issues/694
    ## Some requests take more than 30 seconds.
    proxy_read_timeout      300;
    proxy_connect_timeout   300;
    proxy_redirect          off;

    proxy_set_header    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;

    proxy_pass http://gitlab;
  }

  ## Enable gzip compression as per rails guide:
  ## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
  ## WARNING: If you are using relative urls remove the block below
  ## See config/application.rb under "Relative url support" for the list of
  ## other files that need to be changed for relative url support
  location ~ ^/(assets)/ {
    root /home/git/gitlab/public;
    gzip_static on; # to serve pre-gzipped version
    expires max;
    add_header Cache-Control public;
  }

  # error_page 502 /502.html;

}
1
  • 1
    Please post answers as answers, not as questions. Dec 19, 2014 at 19:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .