# lighttpd wont run in jail



## Anonymous (Jun 4, 2012)

Installed default from ports. No other service listening on port 80 on jail or host system. I put the specific IP address of the jail in lighttpd.conf but when starting the server get 
	
	



```
can't bind to port: 0.0.0.0 80 Address already in use
```
 I don't know what to do and it is even more confusing because the error message makes it look like it didn't even parse the IP address I want from the configuration.


----------



## Beeblebrox (Jun 4, 2012)

You need to define the Jail's IP in the config file. Which you say you have done, but might want to check again. Example:
http://forums.freebsd.org/showpost.php?p=173991&postcount=6
Also you might run into:
http://forums.freebsd.org/showthread.php?t=31422

Re the Jails IP: Have you assigned an existing IP to jail or a different IP? If different have you specified an alias to the NIC for Jail's IP?


----------



## Anonymous (Jun 4, 2012)

Yep server.bind is set to the IP address of the jail. And I know it's reading that config file because *I* tried removing the quotes and it threw all kinds of other errors when attempting to start.

[cmd=]nc -l 80[/cmd] works fine and opens up a socket. Also tried enabling raw sockets just in case but even that made no difference.


----------



## Anonymous (Jun 4, 2012)

I see what's going on here. Problem solved.


----------



## DutchDaemon (Jun 4, 2012)

Which was?


----------



## Unixnut (Feb 16, 2017)

Sorry for dredging up such an old thread, but this is the only hit on Google, and it seems silly to start a new thread about the exact same problem.

So in a nutshell, my situation is exactly the same as the original poster. Setting up lighttpd in a jail. The IP is set in the jail config, the host machine has the IP as one of its aliases, nothing else is running on port 80, and "nc -l 80" works fine. Likewise enabled/disabled raw sockets to no effect.

Always get the same error:


```
# lighttpd -D -f /usr/local/etc/lighttpd/lighttpd.conf
2017-02-16 23:50:19: (network.c.464) can't bind to port: 0.0.0.0 80 Address already in use
```

I tried setting the conf to bind to "localhost", "0.0.0.0" and the actual ip (192.168.24.10), to no avail. Always shows exactly the same error.

EDIT:

Interestingly, setting the lighttpd port to 81 works just fine. So it isn't specific to lighttpd not binding, nor to it being in a jail. There is something about port 80. netstat does not show as anything listening on port 80 either, which makes it all the more odd.  I checked the jail host, and it is also not binding anything to port 80 on that ip addr.

EDIT2:

So, tried setting up a simple web server using Python, which works fine, and I can connect to it:


```
# python2 -m SimpleHTTPServer 80
Serving HTTP on 192.168.24.10 port 80 ...
192.168.42.25 - - [16/Feb/2017 23:59:34] "GET / HTTP/1.1" 200 -
```

So, seems specific to lighttpd interacting with port 80.

EDIT3:

Running through truss, I find that lighttpd attempts to bind both to the ip and 0.0.0.0, despite the config files request.


```
bind(4,{ AF_INET 192.168.24.10:80 },16)        = 0 (0x0)
listen(0x4,0x400)                                = 0 (0x0)
[...]
bind(5,{ AF_INET 0.0.0.0:80 },16)        ERR#48 'Address already in use'
2017-02-17 00:07:45: (network.c.464) can't bind to port: 0.0.0.0 80 Address already in use
```

from what I know, 0.0.0.0 binds to all interfaces. So if it binds once to 192.168.24.10 (and succeeds), then when it next tries to bind to 0.0.0.0 (which includes 192.168.24.10), then it may fail because it is already bound to one of the interfaces. 

Not sure if a software bug, or I am just misunderstanding how freeBSD handles network interface binding.


----------



## Tabs (Feb 17, 2017)

Have you set anything address related in your config besides:

```
server.port = 80
server.bind = "192.168.24.10"
```
?


----------



## Unixnut (Feb 18, 2017)

Nope, I installed lighttpd, and then made the following changes:

```
server.use-ipv6 = "disable"
server.bind = "192.168.24.10"
```

The rest I left as is.


----------



## Unixnut (Feb 18, 2017)

So, in order to get a clearer view, I stripped out the config file:


```
var.log_root    = ""
var.server_root = "/var/www"
var.state_dir   = "/var/run"
var.home_dir    = "/var/spool/lighttpd"
var.conf_dir    = "/usr/local/etc/lighttpd"

var.vhosts_dir  = server_root + "/vhosts"
var.cache_dir   = "/var/cache/lighttpd"
var.socket_dir  = home_dir + "/sockets"

include "modules.conf"

server.port = 80
server.use-ipv6 = "disable"
server.bind = "192.168.24.10"
server.username  = ""
server.groupname = ""

server.document-root = "/var/www/"

server.pid-file = state_dir + "/lighttpd.pid"

server.errorlog             = log_root + "/error.log"

include "conf.d/access_log.conf"
include "conf.d/debug.conf"

server.event-handler = "freebsd-kqueue"
server.network-backend = "writev"
server.max-fds = 2048

server.stat-cache-engine = "simple"
server.max-connections = 1024


index-file.names += (
  "index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)

url.access-deny             = ( "~", ".inc" )

$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi" )


include "conf.d/mime.conf"
include "conf.d/dirlisting.conf"
server.follow-symlink = "enable"
server.upload-dirs = ( "/var/tmp" )


$SERVER["socket"] == "0.0.0.0:80" { }
```

I did notice the following:


```
server.port = 80
server.bind = "192.168.24.10"

$SERVER["socket"] == "0.0.0.0:80" { }
```

Looks like lighttpd has two ways of specifying port and ip binding, no idea why you would have that. As long as you kept both in sync, it would work, but if you change one or the other you would get the error. 

Looks like it did attempt to bind twice, hence the error. 

After commenting out ' $SERVER["socket"] ' , it works. All fixed now, and hopefully will help someone with the same issue in future.


----------

