Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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:, request: "GET / HTTP/1.1", host: ""

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;

    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;
share|improve this question
up vote 11 down vote accepted

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!

share|improve this answer
OMG I feel so stupid now (considering the fact that I have been starring at this for uhhhmmm 'some' while). Thanks for your prompt response! – user6669 May 18 '12 at 0:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.