Hi francis, many thanks for your suggestion, with that i&#39;ve been able to setup a &#39;almost-work&#39; enrivonment!<br><br>I have a file i my /etc/nginx/sites-available/ (softlinket do sites-enabled) that looks as follow:<br>
<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">server{<br>    listen            80;<br>    server_name        ~^(?&lt;domain&gt;.+)\.test\.local$;<br>
    root            /var/www/test_$domain/htdocs;<br>    location / {<br>        index index.php;<br>    }<br>    location ~* \.(gif|jpg|png|ico)$ {<br>        expires    30d;<br>    }<br>    location ~ \.php$ {<br>        fastcgi_pass    unix:/var/run/php5-fpm-test_$domain.sock;<br>
        fastcgi_param    SCRIPT_FILENAME        $document_root$fastcgi_script_name;<br>        include            fastcgi_params;<br>    }<br>}<br></blockquote><div><br>All my subdomains are hosted in /var/www/test_[subdomain_name], for example foo.test.local =&gt; /var/www/test_foo/{htdocs,conf,private}<br>
<br>Then, in my /etc/php5/fpm/fpm.d/ i just create a new file for each subdomain, for example:<br><br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">
[test_foo]<br><br>listen = /var/run/php5-fpm-test_foo.sock<br><br>user = test_foo<br>group = test_foo<br>pm = static<br>pm.max_children = 10<br></blockquote><div><br>..obviously this after i created the unix user `useradd test_foo`.<br>
<br>This isnt the &quot;plug&#39;n&#39;play&quot; behavior i was looking for, becose in order to activate new domains i have to run `/etc/init.d/php-fpm reload`; but i thought a solution: when i add a new domain, i first create a simple &quot;temp&quot; php-cgi process in order to have the subdomain active instantly<br>
<br><blockquote style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class="gmail_quote">php5-cgi -b /var/run/php5-fpm-test_bar.sock<br></blockquote><div><br>Then, running a cron task that every night kill all the php5-cgi instances and then reload the fpm configuration.<br>
<br>Do you think this could be a solution?<br></div></div></div><br><div class="gmail_quote">2011/4/1 Francis Daly <span dir="ltr">&lt;<a href="mailto:francis@daoine.org">francis@daoine.org</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
On Fri, Apr 01, 2011 at 04:14:40PM +0200, Daniele Pignedoli wrote:<br>
<br>
Hi there,<br>
<br>
&gt; Hi guys, im new to Nginx.<br>
<br>
Welcome. You&#39;ll probably want to refer to the manuals for more information<br>
on everything you read here; but for testing purposes, hopefully the<br>
following will help.<br>
<br>
&gt; Im running on a ubuntu 10.04 server machine, and im trying to understand how<br>
&gt; to configure nginx in order to run a website with many subdomains, where<br>
&gt; every of them must run php with a different user, without restarting nginx<br>
&gt; or php5-fpm.<br>
<br>
The short answer is &quot;it&#39;s not a problem; nginx doesn&#39;t know or care<br>
about php&quot;. But that&#39;s not what you want to hear, so...<br>
<br>
&gt; Basically, when i need to a subdomain, i have a script that create the<br>
&gt; server user, then his folder owned by him; for example, for the<br>
&gt; <a href="http://foo.example.com" target="_blank">foo.example.com</a> subdomain i will have a `foo` user and a<br>
&gt; /var/www/vhosts/subdomains/foo/htdocs folder.<br>
<br>
On the nginx side, there are two main ways to approach this.<br>
<br>
Run one nginx instance which can read files of all users; or run one nginx<br>
instance as each user which only has access to that user&#39;s files, plus<br>
one &quot;main&quot; nginx which will proxy_pass to the correct per-user instance.<br>
<br>
The first case is probably easier. An nginx.conf with something like<br>
<br>
===<br>
http {<br>
  server {<br>
    root /tmp/$host/html;<br>
  }<br>
}<br>
===<br>
<br>
will probably do most of what you want. &quot;$host&quot; is &quot;whatever the client<br>
sent in the Host: header&quot; (approximately), so you&#39;ll want to make sure<br>
that nothing nasty happens in edge cases, such as &quot;no Host: header<br>
at all&quot; or &quot;Host: ..&quot; or &quot;Host: *&quot; and the like.<br>
<br>
&gt; So, for every requests to *.<a href="http://example.com" target="_blank">example.com</a>, i need to:<br>
&gt; 1. check if user and folder exists<br>
<br>
&quot;error_page 404&quot; may help here. But it may cause confusion if there are<br>
&quot;genuine&quot; 404s generated.<br>
<br>
&gt; 2. invoke fpm with the matching user/group (maybe the group will be the same<br>
&gt; for every subdomain)<br>
<br>
nginx doesn&#39;t do php. But it does &quot;fastcgi_pass&quot; to a fastcgi server,<br>
which is what fpm is.<br>
<br>
So run one fastcgi server per user, accessible at a derivable<br>
location. And add something like<br>
<br>
===<br>
    location ^~ /php/ {<br>
      fastcgi_pass  unix:/tmp/$host/fcgi.sock;<br>
      include fastcgi.conf;<br>
    }<br>
===<br>
<br>
inside the server{} block, and all requests for /php/something will be<br>
sent to the appropriate fastcgi server (failing if it is not there).<br>
<br>
&gt; Any suggestion about?<br>
<br>
In this example I use $host as the on-filesystem key. You can set that<br>
to something else, if you prefer.<br>
<br>
Also, if you want to run one nginx per user, then you would listen<br>
on a unix socket, and proxy_pass to that socket in the &quot;main&quot; server,<br>
similar to fastcgi_pass above. And it would probably be &quot;error_page 502&quot;<br>
if the per-user server isn&#39;t responding.<br>
<br>
And, I have no idea if FPM has a better way of splitting things per-user<br>
without restarting when users are changed.<br>
<br>
And, of course, none of this is tested by me ;-)<br>
<br>
But if I wanted to do this, I&#39;d probably adjust my &quot;enable user&quot; script<br>
to run a dedicated php fastcgi server as this user, and possibly also<br>
a dedicated nginx server. And then turn them off in my &quot;disable user&quot;<br>
script. The main nginx would run always.<br>
<br>
Good luck with it,<br>
<br>
        f<br>
<font color="#888888">--<br>
Francis Daly        <a href="mailto:francis@daoine.org">francis@daoine.org</a><br>
<br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org">nginx@nginx.org</a><br>
<a href="http://nginx.org/mailman/listinfo/nginx" target="_blank">http://nginx.org/mailman/listinfo/nginx</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Is cuma cá mhinice a théann tú ar strae; is é is tábhachtaí gurb áil leat do bhealach a aimsiú arís.<br>--<br>I can accept failure, everyone fails at something - But I can&#39;t accept not trying. <br>