Welcome! Log In Create A New Profile

Advanced

Re: Shared nginx configuration for multiple servers

Ondrej Jombik
April 06, 2011 01:12PM
I see no technical problems with this. Variable $hostname is known when
the server starts, because with $hostname I mean the name of server
where nginx is running (see gethostname(2) call), not the name of
virtual host (which is unknown on the server start, indeed)

If include is not supported inside if(), I'm pretty sure we are lost.
I see no other way how to accomplish this. Maybe Igor, who knows every
byte of code knows:-)

I think this requirement is a desirable feature. I know guys who
maintain hundreds or thousands of nginx servers. Currently they are
copying configuration files back and forth, but if they were able to
make some per-server configuration alternations based on the same
configuration files set, they would be able to put whole nginx
configuration into SVN and do just "svn update" on certain webservers.

Then every webserver will load its specific configuration (in fact main
configuration with some small per-server differences).

Anyway, thank you for your reply.

Ondrej

On Wed, 6 Apr 2011, Michael Shadle wrote:

> include isn't supported inside of "if" either, I believe.
>
> I wanted to do conditional includes before - but ran into a wall.
> Someone I believe replied to me off list and said they were trying to
> add support for that though.
>
> (I think it might be how the configuration parser works. $hostname is
> unknown when the server starts up, and it includes all the includes at
> the time of start?) I don't know.
>
>
> On Wed, Apr 6, 2011 at 9:51 AM, Ondrej Jombik <jombik@platon.org> wrote:
>> Yes, I can confirm this, it is not evaluated.
>>
>> So probably I need to do:
>>
>>    if ($hostname eq 'servername1') {
>>        include /etc/nginx/conf.d/servername1.conf;
>>    }
>>
>> But I read on MANY places that using if() is evil.
>>
>> Now I do not know what to do.
>> Can some expert suggest a prefered way?
>>
>> Thanks
>>
>> Ondrej
>>
>> On Wed, 6 Apr 2011, Antoine Bonavita wrote:
>>
>>> Hello,
>>>
>>> I'm no expert but from what I can see in the code (ngx_conf_file.c),
>>> the argument to include directive is not "evaluated". So, I would say
>>> the behavior you are seeing is "as expected" although probably not the
>>> one you would like...
>>> May be you can confirm by enabling debug on your install. In the logs
>>> you should see a line like "include <filename>".
>>>
>>> Good luck.
>>>
>>> Antoine.
>>>
>>> On Wed, Apr 6, 2011 at 1:00 AM, Ondrej Jombik <jombik@platon.org> wrote:
>>>>
>>>> We have bunch of servers, where we want to share configuration via SVN
>>>> or GIT (or whatever). So on all server there will be the same
>>>> configuration files set - this is easy to maintain.
>>>>
>>>> Although the most of the configuration is the same on all servers, there
>>>> is a small set of differences for certain servers.
>>>>
>>>> I would like to separate this per-server configuration differences into
>>>> files called $hostname.conf in the conf.d directory.
>>>>
>>>> However this is not working for me:
>>>>
>>>>    include /etc/nginx/conf.d/$hostname.conf;
>>>>
>>>> Is this supposed to work, or not? If not, what is prefered way to
>>>> achieve my goal?

--
Ondrej JOMBIK
Platon Technologies Ltd., Hlavna 3, Sala SK-92701
+421 903 PLATON - info@platon.org - http://platon.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Shared nginx configuration for multiple servers

Ondrej Jombik April 05, 2011 07:02PM

Re: Shared nginx configuration for multiple servers

Antoine Bonavita April 06, 2011 11:58AM

Re: Shared nginx configuration for multiple servers

Ondrej Jombik April 06, 2011 12:52PM

Re: Shared nginx configuration for multiple servers

mike April 06, 2011 12:56PM

Re: Shared nginx configuration for multiple servers

Ondrej Jombik April 06, 2011 01:12PM

Re: Shared nginx configuration for multiple servers

Antoine Bonavita April 06, 2011 02:48PM

Re: Shared nginx configuration for multiple servers

dbanks May 02, 2011 03:04PM

Re: Shared nginx configuration for multiple servers

Maxim Dounin May 02, 2011 03:28PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 253
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready