I need to process with php only some specific urls, like:
http://10.0.0.1/orange
http://10.0.0.1/pear
http://10.0.0.1/apple
any other strings, like:
http://10.0.0.1/orange/
http://10.0.0.1/orangeee
http://10.0.0.1/ora.gif
http://10.0.0.1/orange.php
must be blocked with 404 or 400 (better)
this is my server block:
server {
listen 10.0.0.1:80;
server_name 10.0.0.1;
root /usr/share/nginx/;
location ~ ^ (apple|orange|pear)$ {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/processor.php;
fastcgi_pass 127.0.0.1:9000;
expires -1;
}
}
It doesn works as expected:
Request:
POST http://10.0.0.1/orange
Resonse:
404
The error log reports:
open() "/usr/share/nginx/orange" failed (2: No such file or directory)
p.s. simple locations like:
location /orange {
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/processor.php;
fastcgi_pass 127.0.0.1:9000;
expires -1;
}
works.
Replace the space after the ^
with a /
, making the regex like this ^/(apple|orange|pear)$