简体   繁体   中英

Block apc.php file in nginx

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;
}

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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM