Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I think I have a trivial problem with nginx but I can't see it.

I have the following file tree:

/data/www
> main/
>> html/
>>>...some files (A)

> wiki/
>>...some files (B)

Here is my config:

server {
    listen       80;
    server_name  troll;

    root /data/www/main/html;

    location = / {
        index index.php;
    }

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

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/www/main/html$fastcgi_script_name;
    }

    location /wiki/ {
        root /data/www/wiki;
        rewrite ^/wiki(.*)$ $1 break;
    }

    location ~ ^/wiki/(.*)\.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/www/wiki/$fastcgi_script_name;
    }
}

So, I expect to open files (A) on / urls and (B) files on /wiki urls.

But I have a 403 error on /wiki:

2013/02/12 23:25:06 [error] 30567#0: *58 directory index of "/data/www/wiki/" is forbidden, client: ..., server: ..., request: "GET /wiki/ HTTP/1.1", host: "..."

Even if they have the same rights:

drwxrwx--- 18 apache apache 4096 févr. 10 10:35 /data/www/main/html
drwxrwx---  8 apache apache 4096 déc. 10  2010 /data/www/wiki

and

-rw-r--r-- 1 apache apache 6366 févr.  8 15:10 /data/www/ifaedi/html/index.php
-rw-r--r-- 1 apache apache  185 déc. 10  2010 /data/www/wiki/index.php

If you have any idea...

Edit:

I tried the following configuration:

location /wiki/ {
    root /data/www;
    index index.php;
}

location ~ ^/wiki/(.*)\.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /data/www/$fastcgi_script_name;
}

I have no longer a 403 but php-fpm gives me a "File not found."

2013/02/13 13:06:55 [error] 3876#0: *5 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: ..., server: ..., request: "GET /wiki/ HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "..."

share|improve this question
add comment

2 Answers

Nginx is finding the directory, but not finding an index file and isn't configured to generate directory listings, and so returns an error. You probably want to use try_files to point to your index.php:

location /wiki {
    ..
    try_files $uri $uri/ $uri/index.php?$args;
}
share|improve this answer
    
It changes nothing :/ –  GlinesMome Feb 13 '13 at 11:45
add comment

It sounds like this is a directory index listing problem rather than a permissions issue. Have you tried accessing a file directly instead of the root folder? The error makes sense because your wiki doesn't have an index directive to say which file to load as the index file. If you wanted the path to list all the files you would use the autoindex directive. See http://nginxlibrary.com/enable-directory-listing/ for a good example.

share|improve this answer
    
@mgorven beat me to it and has a much more elegant example. –  Andy Shinn Feb 12 '13 at 22:45
add comment

Your Answer

 
discard

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.