# Freebsd/jail: nginx ignores IP in listen directive

**URL:** <https://www.ruby-forum.com/t/freebsd-jail-nginx-ignores-ip-in-listen-directive/220437>\
**Category:** NGINX\
**Created:** [June 9, 2012, 12:26pm UTC](https://www.ruby-forum.com/t/freebsd-jail-nginx-ignores-ip-in-listen-directive/220437 "2012-06-09T12:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 9, 2012, 12:26pm UTC](https://www.ruby-forum.com/t/freebsd-jail-nginx-ignores-ip-in-listen-directive/220437/1 "2012-06-09T12:26:18Z")

</div>

FreeBSD 8.3/amd64  
nginx 1.2.1  
jail

default config, but listen is:

server {  
listen ip\_addr\_of\_jail:80;  
…  
}

but

$ telnet 127.0.0.1 80  
gets answer from nginx. If I remark this listen directive - nginx isn’t  
answer.

Why nginx listens localhost?

I found something similar to this here:

[http://mailman.nginx.org/pipermail/nginx/2009-February/009947.html](http://mailman.nginx.org/pipermail/nginx/2009-February/009947.html)

but  
server {  
listen 80;  
allow ip\_addr\_of\_jail;  
deny all;  
…  
}

isn’t works too.

Thanks for help.

Posted at Nginx Forum:

> **[Freebsd/jail: nginx ignores IP in listen directive](https://forum.nginx.org/read.php?2,227381,227381#msg-227381)**
>
> FreeBSD 8.3/amd64 nginx 1.2.1 jail default config, but listen is: server { listen ip\_addr\_of\_jail:80; ... } but $ telnet 127.0.0.1 80 gets answer from nginx. If I remark this listen dire

---

<div class="post-metadata">

**Author:** ![zgen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/7ea924/32.png) [@zgen](https://www.ruby-forum.com/u/zgen)\
**Post date:** [June 9, 2012, 5:20pm UTC](https://www.ruby-forum.com/t/freebsd-jail-nginx-ignores-ip-in-listen-directive/220437/2 "2012-06-09T17:20:16Z")

</div>

Hello!

On Sat, Jun 09, 2012 at 06:25:55AM -0400, zgen wrote:

> but
> 
> $ telnet 127.0.0.1 80  
> gets answer from nginx. If I remark this listen directive - nginx isn’t  
> answer.
> 
> Why nginx listens localhost?

Because there is no localhost in a jail, it’s instead emulated by  
the kernel by using jail’s ip instead of localhost. This is how  
jails work, nothing to do with nginx.

> }
> 
> isn’t works too.

This config is expected to resolve the opposite issue: as there is  
no localhost in a jail one can’t listen on it as well (it will  
listen on jail’s ip instead). So to allow only local connections  
it’s not enough to use “listen 127.0.0.1”, the allow/deny  
directives are needed as an additional protection.

Maxim D.
