Location for php except

Hello,

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;
    }

    fastcgi_pass   127.0.0.1:9000;
    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

Phil

On Sun, Jun 01, 2014 at 07:37:51PM +0200, Philipp Kraus wrote:

Hi there,

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$ {
> and for my Gitlab I'm using: > > location /gitlab

The problem at the moment is, that if a PHP file is hosted in a Gitlab
repository the location ~.php$ is matched first.

Strictly, it’s that this location is the one that best matches the
request. (“first” doesn’t really apply.)

See Module ngx_http_core_module for details.

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.

If by “has got the part” you mean “starts with exactly the string”,
then pay particular attention to the “^~” modifier,

(If not, then pay attention to the order of regexes.)

f

Francis D. [email protected]

Am 01.06.2014 um 20:16 schrieb Francis D. [email protected]:

Strictly, it’s that this location is the one that best matches the
request. (“first” doesn’t really apply.)

See Module ngx_http_core_module for details.

okay, I have try to swap both location, imho I have translate “best
location” with “first-come-first-serv order”, so the swap does not
create
any effect.

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.

If by “has got the part” you mean “starts with exactly the string”,
then pay particular attention to the “^~” modifier,

I have added the ^~ to my locations and it seems to be working

Thanks

Phil