Forum: NGINX location for php except

F71657362ed7aff10b7a16c5eec1427c?d=identicon&s=25 Philipp Kraus (Guest)
on 2014-06-01 19:38
(Received via mailing list)
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
36a8284995fa0fb82e6aa2bede32adac?d=identicon&s=25 Francis Daly (Guest)
on 2014-06-01 20:16
(Received via mailing list)
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$ {
<snip>
> 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 http://nginx.org/r/location 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 Daly        francis@daoine.org
F71657362ed7aff10b7a16c5eec1427c?d=identicon&s=25 Philipp Kraus (Guest)
on 2014-06-01 21:00
(Received via mailing list)
Am 01.06.2014 um 20:16 schrieb Francis Daly <francis@daoine.org>:

> Strictly, it's that this location is the one that best matches the
> request. ("first" doesn't really apply.)
>
> See http://nginx.org/r/location 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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.