Hi, I'm trying to setup a php app using fpm (owncloud).
I am trying to match urls which can all over the filesystem and of the
form: something.php/some/path?params
So far I have something like this:
location / {
try_files $uri $uri/ index.php;
}
location ~ ^(?P<script_name>.+\.php)(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.*)$;
if (!-f $script_name) {
#return 404;
break;
}
include fastcgi2.conf;
fastcgi_pass 127.0.0.1:9000;
}
where:
fastcgi2.conf is a copy of fastcgi.conf with one change:
fastcgi_param REQUEST_URI $uri$is_args$args;
How do I avoid using an IF here to check that the php file really
exists? Also, why does uncommenting the return 404 cause some kind of
breakage (not even sure I understand exactly what happens? Seems like
the paths get broken?)
Thanks for any help?
Ed W
on 2013-02-21 18:49
on 2013-02-21 18:55
On Feb 21, 2013, at 21:48 , Ed W wrote: > > where: > fastcgi2.conf is a copy of fastcgi.conf with one change: > fastcgi_param REQUEST_URI $uri$is_args$args; > > > How do I avoid using an IF here to check that the php file really exists? Also, why does uncommenting the return 404 cause some kind of breakage (not even sure I understand exactly what happens? Seems like the paths get broken?) location ~ ^(?<script_name>.+\.php)(?<path_info>/|$) { try_files $script_name =404; include fastcgi2.conf; fastcgi_param PATH_INFO $path_info; fastcgi_pass 127.0.0.1:9000; } -- Igor Sysoev http://nginx.com/support.html
on 2013-02-21 20:09
On 21/02/2013 17:54, Igor Sysoev wrote: > location ~ ^(?<script_name>.+\.php)(?<path_info>/|$) { > try_files $script_name =404; > > include fastcgi2.conf; > fastcgi_param PATH_INFO $path_info; > fastcgi_pass 127.0.0.1:9000; > } Thanks!! Can I ask you to confirm the correction of a typo in your answer. Do I want this: ....(?<path_info>.*) { ie is this ammended version correct in the face of a URL such as: blah.php/some/path?param=2 Thanks Ed W
on 2013-02-22 21:12
On Thu, Feb 21, 2013 at 07:08:56PM +0000, Ed W wrote: > On 21/02/2013 17:54, Igor Sysoev wrote: Hi there, > > location ~ ^(?<script_name>.+\.php)(?<path_info>/|$) { > Can I ask you to confirm the correction of a typo in your answer. Do I > want this: > > ....(?<path_info>.*) { You probably want location ~ ^(?<script_name>.+\.php)(?<path_info>/.*|$) { because you want to match /X.php or /X.php/X but not /X.phpX. f -- Francis Daly francis@daoine.org
on 2013-02-22 23:06
On Saturday 23 February 2013 00:11:26 Francis Daly wrote: > > You probably want > > location ~ ^(?<script_name>.+\.php)(?<path_info>/.*|$) { > > because you want to match /X.php or /X.php/X but not /X.phpX. > IMHO, location ~ ^(?<script_name>.+\.php)(?<path_info>/.*)?$ { looks better. % pcretest -b -d -m -s+ PCRE version 8.30 2012-02-04 re> !^(?<script_name>.+\.php)(?<path_info>/.*|$)! Memory allocation (code space): 42 Memory allocation (JIT code): 1739 ------------------------------------------------------------------ 0 38 Bra 3 ^ 4 15 CBra 1 9 Any+ 11 .php 19 15 Ket 22 9 CBra 2 27 / 29 Any* 31 4 Alt 34 $ 35 13 Ket 38 38 Ket 41 End ------------------------------------------------------------------ Capturing subpattern count = 2 Named capturing subpatterns: path_info 2 script_name 1 Options: anchored No first char Need char = 'p' Subject length lower bound = 5 No set of starting bytes data> re> !^(?<script_name>.+\.php)(?<path_info>/.*)?$! Memory allocation (code space): 40 Memory allocation (JIT code): 1732 ------------------------------------------------------------------ 0 36 Bra 3 ^ 4 15 CBra 1 9 Any+ 11 .php 19 15 Ket 22 Brazero 23 9 CBra 2 28 / 30 Any* 32 9 Ket 35 $ 36 36 Ket 39 End ------------------------------------------------------------------ Capturing subpattern count = 2 Named capturing subpatterns: path_info 2 script_name 1 Options: anchored No first char Need char = 'p' Subject length lower bound = 5 No set of starting bytes wbr, Valentin V. Bartenev -- http://nginx.com/support.html http://nginx.org/en/donation.html
on 2013-02-23 14:42
On Sat, Feb 23, 2013 at 02:05:56AM +0400, Valentin V. Bartenev wrote: > On Saturday 23 February 2013 00:11:26 Francis Daly wrote: > > location ~ ^(?<script_name>.+\.php)(?<path_info>/.*|$) { > location ~ ^(?<script_name>.+\.php)(?<path_info>/.*)?$ { > > looks better. Agreed. And it means I don't have to think about whether AB|C groups as (AB)|(C) or (A)(B|C) in this regex implementation :-) > % pcretest -b -d -m -s+ Using smaller Memory allocation numbers is an extra bonus. Cheers, f -- Francis Daly francis@daoine.org
on 2013-02-24 20:41
On 2013-02-22 23:05, Valentin V. Bartenev wrote: > IMHO, > > location ~ ^(?<script_name>.+\.php)(?<path_info>/.*)?$ { > > looks better. In order to put yet another iteration into the game, I prefer the script_name part to be non-greedy location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ { Of course it still depends on someone's preference what to match in case of /foo.php/bar.php/quux -cs
on 2013-02-25 22:20
On 24/02/2013 19:40, Christoph Schug wrote: > location ~ ^(?<script_name>.+?\.php)(?<path_info>/.*)?$ { > > Of course it still depends on someone's preference what to match in > case of > > /foo.php/bar.php/quux > > -cs You beat me - I was just about to post the same! I think the non greedy is probably the more common case Thanks! Ed W
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.