# Server\_name within tcp server blocks

**URL:** <https://www.ruby-forum.com/t/server-name-within-tcp-server-blocks/243542>\
**Category:** NGINX\
**Created:** [December 2, 2015, 12:31pm UTC](https://www.ruby-forum.com/t/server-name-within-tcp-server-blocks/243542 "2015-12-02T12:31:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 2, 2015, 12:31pm UTC](https://www.ruby-forum.com/t/server-name-within-tcp-server-blocks/243542/1 "2015-12-02T12:31:54Z")

</div>

Hi guys,

I have the following tcp server block in my nginx.conf

stream {  
upstream kafka\_producer {

```
    server kafka.service.consul:9092;
}

server {
    listen 9092;
    server_name kafka.stream.mycompany.com;
    proxy_connect_timeout 10s;
    proxy_timeout 30s;
    proxy_pass kafka_producer;
}

```

}

I would like that my kafka tcp stream is accessible using only the  
[kafka.stream.mycompany.com:9092](http://kafka.stream.mycompany.com:9092) address…just in the same way that it  
works with http server blocks.

However I get the following error regarding the server\_name:

_“server\_name” directive is not allowed here in /etc/nginx/nginx.conf_

So who knows how I can simulate server\_name within tcp server blocks?

Thanks!

---

<div class="post-metadata">

**Author:** ![Charles\_Nnamdi\_Akal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9a140/32.png) [@Charles\_Nnamdi\_Akal](https://www.ruby-forum.com/u/Charles_Nnamdi_Akal)\
**Post date:** [December 2, 2015, 7:16pm UTC](https://www.ruby-forum.com/t/server-name-within-tcp-server-blocks/243542/2 "2015-12-02T19:16:46Z")

</div>

TCP has no concept of server names, so this is not possible. It only  
works  
in HTTP because the client sends the hostname it is trying to access as  
part of the request, allowing nginx to match it to a specific server  
block.

On Wed, Dec 2, 2015 at 12:31 PM, Charles Nnamdi Akalugwu \<

---

<div class="post-metadata">

**Author:** ![Charles\_Nnamdi\_Akal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/e9a140/32.png) [@Charles\_Nnamdi\_Akal](https://www.ruby-forum.com/u/Charles_Nnamdi_Akal)\
**Post date:** [December 2, 2015, 7:47pm UTC](https://www.ruby-forum.com/t/server-name-within-tcp-server-blocks/243542/3 "2015-12-02T19:47:08Z")

</div>

## Richard S. Wrote:

> TCP has no concept of server names, so this is not possible. It only  
> works  
> in HTTP because the client sends the hostname it is trying to access  
> as

To put into better wording,  
The ‘hostname’ technique has 2 parts, part 1 is a receiver (nginx)  
receiving  
a request containing a hostname which it can match (or not) to an item  
in  
its configuration, and part 2 the DNS name where this name is recorded  
against its IP address. With stream{} you can only rely on part 2.

Posted at Nginx Forum:  
[https://forum.nginx.org/read.php?2,263208,263219#msg-263219](https://forum.nginx.org/read.php?2,263208,263219#msg-263219)
