UserDir

I’m having trouble getting UserDir to work. I think it has something to
do
with the PHP fastcgi options. Can someone please take a look at my
configuration and double check what I have? Any help is appreciated.
Thanks.

On Wed, Feb 01, 2012 at 11:31:14AM -0500, Brad Huntington wrote:

Hi there,

I’m having trouble getting UserDir to work. I think it has something to do
with the PHP fastcgi options. Can someone please take a look at my
configuration and double check what I have? Any help is appreciated. Thanks.

What’s the trouble you’re seeing?

GET /~user/file fails? Or GET /file.php fails? Or GET /~user/file.php
fails?

user nobody;worker_processes 4;worker_rlimit_nofile 8192;events{ - Pastebin.com

In nginx, each request is handled by exactly one location{} block. Only
the configuration in, or inherited into, that location{} matters.

You have one regex location for .php urls, and one regex location for
“userdir” urls. A single request won’t match both of those.

If you can describe your desired url->file mapping, it will likely be
easier to ensure that the nginx.conf matches that.

Good luck,

f

Francis D. [email protected]

Hello,
I have a very similar problem. I want to use userdirs as in apache and
as described here: http://wiki.nginx.org/UserDir and use php with
fast-cgi in these userdirs. I’ve tried it with this:

    location ~ ^/~(.+?)(/.*)?$ {
        alias /home/$1/public_html$2;
        index  index.html index.htm;
        autoindex on;
        location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

But it get empty pages, when I try to call a php-file.
How can I get php files with match this location to be forwarded to
fast-cgi?

Posted at Nginx Forum:

On Wed, Feb 1, 2012 at 11:31 PM, Brad Huntington
[email protected] wrote:

I’m having trouble getting UserDir to work. I think it has something to do
with the PHP fastcgi options. Can someone please take a look at my
configuration and double check what I have? Any help is appreciated. Thanks.

user nobody;worker_processes 4;worker_rlimit_nofile 8192;events{ - Pastebin.com

note that using this config, anyone can read (and possibly write)
others’ files with little effort thanks to php process running as
single user.


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Thank you,
even though I understand it only partially it works.
But directory listing doesn’t work anymore (e.g.
http://localhost/~white_gecko/) I get 404.

Posted at Nginx Forum:

Try this → http://pastie.org/4169064

Posted at Nginx Forum:

On 02-16 16:57, white_gecko wrote:

            fastcgi_index index.php;
            include fastcgi_params;
        }
    }

But it get empty pages, when I try to call a php-file.
How can I get php files with match this location to be forwarded to
fast-cgi?

If you take a look into the fastcgi_params file you’ll notice that the
following or something similar is written:

fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

$request_filename in your case is something like this:

/~white_geko/some/where/is/my/script.php

$fastcgi_script_name:

/~white_geko/some/where/is/my/script.php

so, this is not the correct path to find this file on the filesystem, so
we
map it:

^/~([^/]+)(/.*).php

$1 is the username

$2 is the filename + relative path

so, we set the document_root to your public_html directory, which is
somehow
correct if your php script is placed in your public_html directory.

root /home/$1/public_html;

next we set the correct script_name which is relative to the
document_root. We
add an .php, because it is not included in our match($2)

fastcgi_param SCRIPT_NAME $2.php;

After this all php-fpm needs to know is where is the file located.

fastcgi_param SCRIPT_FILENAME $document_root$2.php;

when i sniffed the traffic between nginx <-> php-fpm i noticed that
fastcgi_param only adds more parameters to the communication. it does
not
replace the old values. so i dropped the include of the params out and
added
all variables right in this location.

The complete config section, try this:

location ~ ^/~([^/]+)(/.*)\.php$ {
    root /home/$1/public_html;
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param   SCRIPT_NAME             $2.php;
    fastcgi_param   SCRIPT_FILENAME         $document_root$2.php;
    fastcgi_param   QUERY_STRING            $query_string;
    fastcgi_param   REQUEST_METHOD          $request_method;
    fastcgi_param   CONTENT_TYPE            $content_type;
    fastcgi_param   CONTENT_LENGTH          $content_length;

    fastcgi_param   REQUEST_URI             $request_uri;
    fastcgi_param   DOCUMENT_URI            $document_uri;
    fastcgi_param   DOCUMENT_ROOT           $document_root;
    fastcgi_param   SERVER_PROTOCOL         $server_protocol;

    fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
    fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

    fastcgi_param   REMOTE_ADDR             $remote_addr;
    fastcgi_param   REMOTE_PORT             $remote_port;
    fastcgi_param   SERVER_ADDR             $server_addr;
    fastcgi_param   SERVER_PORT             $server_port;
    fastcgi_param   SERVER_NAME             $server_name;
}

location ~ ^/~([^/]+)(/.*)?$ {
    if ( !-d /home/$1/public_html ) {
        return 404;
    }
    index  index.html index.htm index.php;
    autoindex on;
}

Hope that works for you :slight_smile:

bye MUH!


;;,
)…(
=_)
(oo)| |