0

I need to setup a virtual host to run my users.example.com website. It needs PHP support via php-fpm. The ideia is to have a mapping like this:

users.example.com/~user1/folder/file.php -> /home/user1/www/folder/file1.php users.example.com/user1/folder/file.php -> /home/user1/www/folder/file1.php users.example.com/~user2/stuff/about.html -> /home/user2/www/stuff/about.html

et cetera. Each users files run under a different PHP-FPM pool (so, a different fpm socket), for security reasons. The socket has a full path off /var/run/{USERNAME}_fpm.sock. How can I make this server configuration?

Initial idea is to have a server { }, with server_name users.example.com; and a location with a different root for each user. I'd like to know if that works and the setup for it to work.

1 Answer 1

0

I haven't tested this myself, but something like this could work

server { server_name users.example.com; listen 80; location ~ /(?:~)?(?<user>[a-zA-Z0-9]+)/ { alias /home/$user/www/; fastcgi_pass /var/run/$user_fpm.sock; } } 

So, in the location line, we capture the username to the $user variable, and then use the variable for the alias and fastcgi_pass directives. You can also expand the regular expression for the user home directory if you want to include more characters in it.

The (?:~)? part matches the optional ~ character in the pathname.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.