Welcome! Log In Create A New Profile


Re: UserDir

Sven Ludwig
February 16, 2012 06:38PM
On 02-16 16:57, white_gecko wrote:
> 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;
> 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:




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


$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_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 :)

bye MUH!

(oo)| |

nginx mailing list
Subject Author Posted


bhuntington February 01, 2012 11:32AM

Re: UserDir

Edho Arief February 01, 2012 12:28PM

Re: UserDir

Francis Daly February 01, 2012 12:32PM

Re: UserDir

white_gecko February 16, 2012 04:57PM

Re: UserDir

Sven Ludwig February 16, 2012 06:38PM

Re: UserDir

white_gecko February 17, 2012 04:40AM

Re: UserDir

sistematico June 28, 2012 10:23PM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 66
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready