variables in "include" for vhost specific config files

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

variables in "include" for vhost specific config files

Kaspars
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.

Reply | Threaded
Open this post in threaded view
|

Re: variables in "include" for vhost specific config files

Igor Sysoev
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/

Reply | Threaded
Open this post in threaded view
|

Re: variables in "include" for vhost specific config files

Michael Shadle
2009/7/21 Igor Sysoev <[hidden email]>:

> 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  ...

The only negative about this is (how Maxim described it) any "array"
type configuration item like fastcgi_param will be reset if you set
this globally, but then add a new index somewhere else.

I set all my fastcgi_params globally in the past, but then I needed to
set fastcgi_param HTTPS on; just for a single server block - and what
happens is the entire set gets reset to nothing besides the HTTPS one.
I thought it would override a value (which it appears to properly) or
add a value.

Of course, one could just set fastcgi_param HTTPS off; and then just
override it on the server, but it is something to caution people
about, unless that behavior has been modified (this was recent though)

Also, I had my fastcgi_params set globally and it appears that my
Django setup (I believe it was) wanted a couple different params and
did not like me defaulting fastcgi_index index.php (which was set
globally), so I wound up doing the separate fastcgi_params config file
(I should call it php.conf) and including it inside of every location
block for php. That guarantees I can add new items like HTTPS on too -
the array structure isn't killed if it is inside of the same location
block it seems...