Rafa_F
1
Hi,
Based on scraps found in the NGINX docs, I have a semi-working config
that looks as follows :
location /demo {
allow 10.0.0.0/8;
deny all;
try_files $uri @pdemo;
}
location @pdemo {
fastcgi_param SCRIPT_FILENAME /path/to/demo.php;
fastcgi_param SCRIPT_NAME /demo.php;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_param QUERY_STRING $args;
include fastcgi_params;
}
I say this config is “semi-working” because :
A base-call to http://example.com/demo returns the hello-world output
from my PHP router. No problems there.
But, if I call, say, http://example.com/demo/hello/x, the PHP router
doesn’t match the route (despite expecting hello/x as the path).
If it helps, I’m using bramus router and my configured paths are as
follows :
$router->get(‘/’, function() { echo “hello world”};
$router->get(‘hello/(\w+)’, function($name) {echo “hello”.$name};
However bramus returns a 404, and it doesn’t matter if I prefix the
hello path with a forwad slash in bramus.
Therefore I am guessing my nginx config is broken ?
ben
2
Hi
On Wed, Jun 15, 2016, at 02:28, Ben wrote:
}
follows :
Looks like the logic for getting base path is a bit interesting. Try
this for related line:
fastcgi_param SCRIPT_NAME /demo/;
ben
3
Hi
On Thu, Jun 16, 2016, at 22:06, Ben wrote:
for /demo/hello/x it prints “/demo/hello”
Which looks like their “auto base-path” is setting moving goalposts !!
That doesn’t make sense if you actually use my configuration since
SCRIPT_NAME is static.
ben
4
If it helps, I’m using bramus router and my configured paths are as
follows :
Looks like the logic for getting base path is a bit interesting. Try
this for related line:
fastcgi_param SCRIPT_NAME /demo/;
That didn’t work unfortunatley.
Just dug up their code and I see what you mean !
I put their “implode(’/’, array_slice(explode(’/’,
$_SERVER[‘SCRIPT_NAME’]), 0, -1)) . ‘/’;” into my PHP and
for /demo/ it prints “/demo/”
and
for /demo/hello/x it prints “/demo/hello”
Which looks like their “auto base-path” is setting moving goalposts !!
Any other alternative NGINX configs I could try ? I’ve tried reporting
their base path but they’re not particularly interested in fixing it!
I have also tried :
try_files $uri $uri/ /demo/demo.php;
But that only seems to work intermittently (which I guess is why NGINX
recommend the original method I posted !).
ben
5
Hi
On Thu, Jun 16, 2016, at 22:11, Edho A. wrote:
Looking again, you probably need to include fastcgi_params first.
Here’s the config I’m using:
12 location @pdemo {
13 include fastcgi_params;
14 fastcgi_param SCRIPT_FILENAME /path/to/demo.php;
15 fastcgi_param SCRIPT_NAME /demo/;
16 fastcgi_pass 127.0.0.1:9000;
17 }
ben
6
On 16/06/2016 14:14, Edho A. wrote:
14 fastcgi_param SCRIPT_FILENAME /path/to/demo.php;
15 fastcgi_param SCRIPT_NAME /demo/;
16 fastcgi_pass 127.0.0.1:9000;
17 }
nginx mailing list
[email protected]
nginx Info Page
Doing some testing but that seems to have done the trick in the few
things I’ve tried so far.
Thanks !