Question

I am trying to block the apc.php file on my webserver. If do the following it works but I am thinking there is a better way to do this and put the deny/allow rule below the general location ~ .php$ block. It doesnt seem right to have to have two blocks with the fastcgi params.

#Block to apc.php
location ~ /apc.php {

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

    allow 192.168.3.0/24;
    deny all;
}

# use fastcgi for all php files
location ~ \.php$
{
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

No correct solution

OTHER TIPS

Since "deny" not allowed in if statement, you can use nested location like location / { location /uri/ {} }, however, it is not encouraged in Nginx manual:

"While nested locations are allowed by the configuration file parser, their use is discouraged and may produce unexpected results."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top