Should we add php-fpm for each Virtual Host or in Global Configuration ?

Anoop Alias anoopalias01 at gmail.com
Wed Aug 12 08:20:34 UTC 2015


Please see http://nginx.org/en/docs/http/ngx_http_core_module.html#location

location should be in a server or location context .So you cannot define it
outside of all the server context's.

One thing you can do is define a single location block for php and include
it in every server context which will save you the trouble of adding it
everytime.

But note that in real life you may need to change the fastcgi_pass to
different pools defined in php-fpm to separate php process based on user
etc.



On Wed, Aug 12, 2015 at 8:07 AM, sunzeal <nginx-forum at nginx.us> wrote:

> This is my configuration for my Virtual Host. I am not sure, but is this
> the
> ideal way of defining things ?
>
> For every domain / sub-domain, i'm adding a location ~/.php directive.
> Should i add it in the global nginx.conf itself instead of specifying
> individually for each domain i add ?
>
> Sample Configuration :-
>
>
> server {
>     listen       80;
>     server_name  example.com;
>
>  location / {
>         root         /var/www/example.com;
>         index  index.php;
>
>     }
>
>
> location ~ \.php$ {
>         root           /var/www/example.com/;
>         fastcgi_pass   127.0.0.1:9000;
>         fastcgi_index  index.php;
>        # fastcgi_read_timeout 30000;
>        # fastcgi_param  SCRIPT_FILENAME $fastcgi_script_name;
>         fastcgi_param  SCRIPT_FILENAME $request_filename;
>         include        fastcgi_params;
>     }
>
> server {
>     listen       80;
>     server_name www.example.net;
>
>  location / {
>         root           /var/www/example.net/;
>         index  index.php;
>
>     }
>
>
> location ~ \.php$ {
>         root           /var/www/example.net/;
>         fastcgi_pass   127.0.0.1:9000;
>         fastcgi_index  index.php;
>        # fastcgi_read_timeout 30000;
>        # fastcgi_param  SCRIPT_FILENAME $fastcgi_script_name;
>         fastcgi_param  SCRIPT_FILENAME $request_filename;
>         include        fastcgi_params;
>     }
>
> Posted at Nginx Forum:
> http://forum.nginx.org/read.php?2,260943,260943#msg-260943
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>



-- 
*Anoop P Alias*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20150812/41a667ae/attachment.html>


More information about the nginx mailing list