Conditionals in fastcgi config

Igor Clark igor at
Tue Oct 30 19:04:45 MSK 2007

Hi Igor and nginx people,

We use nginx as a front end on various development machines in our  
studio to route to installations of Apache 1, Apache 2, PHP/FCGI, and  
Ruby/Mongrel on each machine, as appropriate depending on SERVER_NAME  
conventions, using our private DNS domain.

We have some circumstances under which we need to grant external  
access to machines with this setup, and we do this using Apache  
reverse proxy on the firewall. (Eventually this will be replaced by  
nginx, but it's got a lot of legacy stuff which will need some time  
set aside for converting.) Hence is  
proxied through to

This means that the SERVER_NAME value seen by the web application  
(PHP script in this case) is

We often configure web applications on a per-host basis, so that e.g.  
database configuration information is kept in a hash keyed by  
SERVER_NAME values. This means we need to have SERVER_NAME contain  

We've achieved this straightforwardly by setting

	fastcgi_param	SERVER_NAME	$http_x_forwarded_host;

which works nicely, but means that all applications responding to  
different DNS names (not viewed externally via Apache reverse proxy)  
fail, because they don't have an X-FORWARDED-HOST header, thus fall  
back to the local machine hostname, which is not in the configuration  

We can get round this by creating separate server {} configurations  
for applications which need to be served behind a remote reverse  
proxy, but that defeats the object of our generic per-host  
configuration based on hostnames.

So ideally I'd like to do something like:

	fastcgi_param	SERVER_NAME	$server_name;
	if ($http_x_forwarded_host) {
		fastcgi_param	SERVER_NAME	$http_x_forwarded_host;

but: firstly "fastcgi_param" is not supported inside "if", and  
secondly I don't know how or if this "overriding" would work.

What's the best way to do this, please?

Thanks very much

Igor Clark // POKE // 10 Redchurch Street // E2 7DD // +44 (0)20 7749  
5355 //

Get on Board with WWF for a stronger Climate Change Bill

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list