variables in "include" for vhost specific config files

Igor Sysoev is at rambler-co.ru
Tue Jul 21 13:05:53 MSD 2009


On Sun, Jul 19, 2009 at 08:45:07PM +0300, Kaspars wrote:

> Privet Igor and dear list members,
> 
> I am trying to create a flexible virtual host environment, where each 
> host could have their own config.nginx file.
> 
> In sites-available/default I have:
> 
> server {
>         listen   80 default;
>         server_name _;
>         server_name_in_redirect off;
> 
>         set $vhost_path /var/www/vhosts;
> 
>         root    $vhost_path/$host;
>         index   index.php index.html index.htm;
> 
>         # THE IMPORTANT BIT: vhost specific config files, for rewrites, 
> etc.
>         include /var/www/vhosts/$host/config.nginx;
> 
>         [...]
> }
> 
> 
> 'root' directive works fine, but the 'include' doesn't like the $host 
> variable in it.
> 
> I would like to avoid using server { ... } for each of the individual 
> hosts, in order to have global php settings.
> 
> What would be the best way to approach this?
> 
> Any pointers and suggestions are very welcome.
> 
> Regards,
> Kaspars
> 
> p.s. using nginx 0.6.32-3 on debian lenny.

As it was already discussed, nginx "include"s files on start time,
while "root", etc. substitute variable values on run time.

As to global php settings, you may use

http {

     # here you may set any fastcgi settings expect fastcgi_pass,
     # and they will be inherited in all servers and locations.
     fastcgi_index  ...
     fastcgi_param  ...

     server {
         ...

         location \.php$ {
             fastcgi_pass   ...;
         }
     }

     server {
         ...

         location \.php$ {
             fastcgi_pass   ...;
         }
     }

My personal paractice is always to use separate servers since it allows
to change their configuration without risk to break others.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list