문제

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)$

다른 팁

You have a space in your regex: ^ (apple|orange|pear)$

Remove the space after ^.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top