Set nginx.conf to deny all connections except to certain files or directories

Posted by Ben on Server Fault See other posts from Server Fault or by Ben
Published on 2011-01-15T15:49:10Z Indexed on 2011/01/15 15:55 UTC
Read the original article Hit count: 277

Filed under:
|
|
|

I am trying to set up Nginx so that all connections to my numeric ip are denied, with the exception of a few arbitrary directories and files. So if someone goes to my IP, they are allowed to access the index.php file, and the phpmyadmin directory for example, but should they try to access any other directories, they will be denied.

This is my server block from nginx.conf:

server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm index.php;
        }

        location ~ \.php$ {
            root           html;
            fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME /srv/http/nginx/$fastcgi_script_name;
            include        fastcgi_params;
        }
}

How would I proceed? Thanks very much!

© Server Fault or respective owner

Related posts about linux

Related posts about webserver