Welcome! Log In Create A New Profile

Advanced

User Home Dirs

Posted by shawn-northrop 
User Home Dirs
June 30, 2015 03:52PM
I am trying to configure nginx so that when going to `http://example.com/~user/` it will load files from the `/home/~user/www/` directory.

I have found a script that seems to work for .html files but returns 404 errors on .php files. I think it has to do with the `~\.php` block in my conf file but am not really sure how to resolve.

Here is my default.conf file:

//nginx config

server {
listen 80;
server_name example.com;

root /home/example.com/www;
index index.php index.html index.htm;

location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/example.com/web;
}

/////
//user home directory code

location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/www$2;
autoindex on;
index index.php index.html
}

////

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 140
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready