-1

I bought the linode(linode.com) server the other day. I've been trying to run lighttpd and apache2 at the same port, using lighttpd for static files. As linode is only providing ONE ipv4 address, I tried to bind lighttpd on the ipv6 address. That's where I got the same error each and very single time: can't bind to port [ipv6] 80 Address already in use. I tried bind the ipv4 address. Everything worked. Please help me, this is driving me nuts for the last two days.

my lighttpd.conf file:(the ipv6 address isn't true)

server.modules = (
    "mod_access",
    "mod_alias",
    "mod_compress",
    "mod_redirect",
#       "mod_rewrite",
)

server.document-root        = "/var/www"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80
server.bind         = "2600:3c02::0000"
server.use-ipv6         = "enable"
#server.pid-file            = "/var/run/lighttpd.pid"


index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"


### ipv6 ###
$SERVER["socket"] == "[2600:3c02::0000]:80" {
#   accesslog.filename  = "var/log/lighttpd/ipv6/access.log"    
#   server.document-root = "/var/www/"
#   server.error-handler-404 = "/index.php?error=404"
}

and the error message: can't bind to port, 2600:3c02::0000 Address already in use.

Jenny D
  • 27,358
  • 21
  • 74
  • 110
Hans Xeng
  • 3
  • 3
  • Did you check what ports apache is listening on? If you don't specify which IP address it should bind to, it will listen on all available interfaces, including the IPv6 one. – Jenny D Oct 25 '13 at 08:32
  • apache2 is listening on the ipv4 address. If works fine. The problem with lighttpd persists, I tried stop the apache2, even removed it. Still got the same problem. – Hans Xeng Oct 25 '13 at 08:54

2 Answers2

2

If you want to serve static files by lighttpd/nginx and dynamic by apache, you have to run lightttpd/nginx on port 80 (or 443, if ssl), and apache on something else. You then configure lightttpd/nginx as proxy to forward everything that is not static to apache on the alternative port. There are plenty of examples to find.

Halfgaar
  • 7,921
  • 5
  • 42
  • 81
  • You mean I'll need to make apache listen on another port? But the problem is, no I have removed apache and runing only lighttpd. When bind it to a ipv4 address, no problem, when try to bind to ipv6, error. I've been developping my site on my archlinux server for a couple of months which was install on the local machine. I used two LAN ip addresses(192.168.1.101,192.168.1.110), everything worked. But linode is providing only on ipv4. Maybe I should buy another ipv4? – Hans Xeng Oct 25 '13 at 09:01
  • If you need to support ipv4 connections, the best option is that proxy. You could also run static on another port using the same IP, but then your source code has to reference `static.site.net:81` for instance, and that may not work on all your visitors connections, due to security restrictions, for example. But, can you show the listen directive in your apache conf? And what does `netstat -lpt` say? – Halfgaar Oct 25 '13 at 10:21
1

You bind to [2600:3c02::0000]:80 with

server.port                 = 80
server.bind         = "2600:3c02::0000"

and

$SERVER["socket"] == "[2600:3c02::0000]:80" {
...
}

This means you bind twice to the same address. Remove the $SERVER["socket"] block and you should be fine.

(Edit: That way you get what you asked for; but I doubt your "setup" in general is a good idea; as Halfgaar pointed out, one webserver has to proxy to the other; usually the one serving the static files should be the public visible one, proxying to the other hidden one)

Stefan
  • 819
  • 1
  • 7
  • 18