Im pretty new to nginx and – more for learning purpose – im trying to configure Nginx in order to run php with a different user for every subdomains.
For example, i would like to use user john
for all scripts on foo.example.com
and user jack
for bar.example.com
.
I have already created the user on my system (ubuntu server), but i dont know how to instruct nginx to use the users – and im looking for a solution tht can handle easly many users, lets say ~2000.
Looking the documentation, i dont understand if i have to spawn a php5-cgi
process for every user (with a different port) and then grab them into my sites-available
sites (as i said im a newbie, but this looks to me like a server-suicide), and the only 2 pages in the nginx configuration that talk about that.. is written in chinese (page1, page2), hard to translate with google translate (but, looking the codes, uses a totally different from the server-suicide
way)
Any suggestion?
Update
galador's answer do the job, but im trying to build a dinamycal environment (with wildcards subdomains) that doesnt need torestart nginx/fpm for every new site, is this possible?
Best Answer
Edit: I just noticed your "needs to scale to ~2000 users" requirement... this might not be your best option, but could probably be easily automated with a bit of scripting.
You could use php-fpm to do something like this (fpm is part of the PHP since PHP 5.3.3. I host a couple of sites on my VPS, and use something similar.
My main php-fpm.conf looks like:
And then, in the fpm.d folder, I have configuration files for each site like this:
Then, for each site, you change the user and the port in their own file, and in the nginx config, you'd have something like:
Changing the port in the fastcgi_pass directive.