location for php except

Philipp Kraus philipp.kraus at tu-clausthal.de
Sun Jun 1 17:37:51 UTC 2014


I'm using nginx with Gitlab, so in the Gitlab some PHP projects are hosted and on other directory there exists some PHP scripts.

For the PHP files I use:

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name)
            return 404;
        include /etc/nginx/fastcgi_params;
        try_files $uri $uri/ =404;

and for my Gitlab I'm using:

location /gitlab
        alias       /home/gitlab/gitlab/public;
        try_files   $uri @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;

The problem at the moment is, that if a PHP file is hosted in a Gitlab repository the location ~\.php$ is matched first.
So how can I change the locations, that all PHP files, which URL has got the part /gitlab it should be passed to Gitlab and
otherwise it should be passed to the fastcgi call e.g.

myserver/gitlab/user/repository.git/master/test.php should be handled by Gitlab and myserver/somedirectory/test.php should be
handled by the fastcgi call.

Thanks a lot


More information about the nginx mailing list