Shared nginx configuration for multiple servers

Maxim Dounin mdounin at
Mon May 2 23:26:17 MSD 2011


On Mon, May 02, 2011 at 03:04:48PM -0400, dbanks wrote:

> I'm facing a related issue, although my attempt at implementation is
> different from the OP.
> ip.conf:
> set $server_ip;
> nginx.conf:
> ...
> server { 
>         include ip.conf;  #adds the $server_ip variable which is
> machine-specific
>         listen  $server_ip:80 default_server;
> ...
> }
> This fails with:  nginx: [emerg] host not found in "$server_ip:80" of
> the "listen" directive in /opt/nginx/conf/nginx.conf:48
> What is the best way to include a hard-coded IP address from another
> file in order to allow nginx.conf to be universal across deployed
> machines?

Variable are evaluated at runtime during request processing, you 
can't use them to configure listening sockets.

Either place full listen directive in included file or use some 
external scripting to produce actual config.

Maxim Dounin

More information about the nginx mailing list