block access to a file !!

torajx nginx-forum at
Wed Jun 6 13:22:50 UTC 2012

it must be a piece of cake but i can not find a soloution...

the problem is " location admin.php". you can check it below...

i just want to allow access to admin.php to some ip address and deny

if i remove allow line from it it deny all; but when I add allow line it
dont work ..
please help me...
I tried too many syntax but no success.
i even add root and index to this location but browser prompt to
download my php file..

please help

here 's my server section of config...very simple
server {
        listen       80;
        server_tokens off;
        access_log  /var/log/nginx/mysite.log;
        error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;

        location / {
           root /usr/share/nginx/www;
           index  index.php;
           client_max_body_size 8m;
           client_body_buffer_size 256k;
       location = /50x.html {
           root /usr/share/nginx/html;
        location = /404.html {
           root /usr/share/nginx/html;
        location ~ /\.ht {
            deny  all;
        location ~ \.php$ {
            root /usr/share/nginx/www;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME 
            include       fastcgi_params;
            set $ssl off;
            if ($ssl_protocol != "" ) {
               set $ssl on;
            fastcgi_param   HTTPS                   $ssl;

        location ~ admin.php {
             deny all;

Posted at Nginx Forum:,227281,227281#msg-227281

More information about the nginx mailing list