# Setting server name = hostname explicitly

**URL:** <https://www.ruby-forum.com/t/setting-server-name-hostname-explicitly/201911>\
**Category:** NGINX\
**Created:** [January 17, 2011, 8:26pm UTC](https://www.ruby-forum.com/t/setting-server-name-hostname-explicitly/201911 "2011-01-17T20:26:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 17, 2011, 8:26pm UTC](https://www.ruby-forum.com/t/setting-server-name-hostname-explicitly/201911/1 "2011-01-17T20:26:37Z")

</div>

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:

> **[setting server\_name = hostname explicitly](https://forum.nginx.org/read.php?2,167013,167013#msg-167013)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![spurcell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@spurcell](https://www.ruby-forum.com/u/spurcell)\
**Post date:** [January 21, 2011, 1:33pm UTC](https://www.ruby-forum.com/t/setting-server-name-hostname-explicitly/201911/2 "2011-01-21T13:33:31Z")

</div>

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.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![spurcell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/8edcca/32.png) [@spurcell](https://www.ruby-forum.com/u/spurcell)\
**Post date:** [January 25, 2011, 5:56pm UTC](https://www.ruby-forum.com/t/setting-server-name-hostname-explicitly/201911/3 "2011-01-25T17:56:13Z")

</div>

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:

> **[Re: setting server name = hostname explicitly](https://forum.nginx.org/read.php?2,168226,169452)**
>
> On Mon, Jan 17, 2011 at 02:24:42PM -0500, spurcell wrote: \> 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...
