Nginx – 403 Forbidden when trying to reach the simple test page

nginx

I've just installed nginx and I'm trying to setup my first site. I'm trying to use nginx with php-fpm. nginx is installed (when I go to my ip I get the default welcome to nginx page).

Now I am trying to get a simple script running:

<?php
phpinfo();

But I keep hitting a 403 Forbidden page. In the log of my virtual host I can see lots of lines like:

2012/05/18 01:29:45 [error] 4272#0: *1 access forbidden by rule, client: x.170.147.49, server: example.com, request: "GET / HTTP/1.1", host: "example.com"

The file is /srv/www/test/index.php of which nginx is the owner (I went as for as 777ing the complete path including the file to no avail).

I have checked that nginx is indeed running under user and group nginx/nginx in the config and it is. In the nginx.conf I've changed the default config include path to make sure no other config get in the way (include /etc/nginx/sites-enabled/).

The config I am using looks like (if you need other configs (php-fpm / nginx.conf) please let me know):

server {
    listen 80;

    server_name example.com;
    root /srv/www/test;
    access_log /var/log/nginx/example-access.log;
    error_log  /var/log/nginx/example-error.log error;

    location ~ /.          { access_log off; log_not_found off; deny all; }
    location ~ ~$           { access_log off; log_not_found off; deny all; }

    location ~* .(js|css|png|jpg|jpeg|gif|ico|xml|swf|flv|eot|ttf|woff|pdf|xls|htc)$ {
        add_header Pragma "public";
        add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        access_log off;
        log_not_found off;
        expires   360d;
    }

    location ~ /.ht {
        deny all;
        access_log off;
        log_not_found off;
    }

    location ~ /. {
        access_log off;
        log_not_found off;
        deny all;
    }

    location ~ ^/(index|frontend_dev|admin|staging).php($|/) {
        #rewrite ^/(.*)/$ /$1 permanent;
        fastcgi_split_path_info ^(.+.php)(.*)$;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;

    }

    location / {
        index index.php;
        try_files $uri /index.php?$args;
    }
}

Best Answer

Your config is intentionally blocking it:

location ~ /. {
    access_log off;
    log_not_found off;
    deny all;
}

That'll match any request where a slash is followed by a character of any kind; the . character in a regular expression means "any character".

I'm assuming you meant to check for a literal .; that'd be this config:

location ~ /\. {

Let me know if that's not the case!