0

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: "..."

2 Answers 2

1

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;
}
1
  • It changes nothing :/
    – GlinesMome
    Feb 13, 2013 at 11:45
0

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.

1
  • @mgorven beat me to it and has a much more elegant example.
    – Andy Shinn
    Feb 12, 2013 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .