Setting server name = hostname explicitly

Hi everyone,

If Igor’s reading, I just want to say that NGINX is amazing and we love
it. Thank you!

Apologies if this has already been answered elsewhere, but I spent a lot
of time looking and couldn’t find a solution: is there any way to
specify the current hostname as a valid server_name explicitly without
using a literal? I know this is what you get if you just leave
server_name unspecified, but then I can’t also have it match
“localhost”, without it being the default server.

So I guess my question could be rephrased as: how can I set up a server
to match requests to “localhost” and whatever the machine’s hostname is
without hard-coding the hostname in the config file or making the server
the default. (I don’t want the server to be the “default” server for
port 80; I want another server to do that.)

server_name $hostname; doesn’t appear to work, and neither does
server_name ~$hostname; and I’d like to avoid regex processing overhead
anyway. I guess ideally what I’d like would be:

server_name $hostname localhost;

or something like that. And if neither matched, it would fall through to
the default server.

Thanks and sorry if I’m just being obtuse,
Seth

Posted at Nginx Forum:

On Mon, Jan 17, 2011 at 02:24:42PM -0500, spurcell wrote:

“localhost”, without it being the default server.

server_name $hostname localhost;

or something like that. And if neither matched, it would fall through to
the default server.

Changes with nginx 0.9.4 21 Jan
2011

*) Feature: the "server_name" directive supports the $hostname 

variable.


Igor S.
http://sysoev.ru/en/

I can’t imagine a commercial software vendor responding to a support
question with an enhancement.

Igor, we owe you a bottle of something nice - maybe something that’s
hard to find in Russia?

Seth

Posted at Nginx Forum: