0

I have a question regarding lighttpd best practices for vhosts setups. I wanted to set up a modular config for several vhosts with splitted config files to be able to enable/disable specific vhosts easily. Platform is Debian 8.2 running lighttpd 1.4.35. Requirements are as follows:

  • the server should bind to a public NIC and listen on port 80 for the public vhosts
  • it also should listen on port 81 for machine2machine communication only
  • additionally it should bind to a NIC on an internal network (both ports 80/81)
  • vhosts should be defined in separate files under conf-enabled/vhostN.conf

So I did set up as follows (1.2.3.4 be the IP of the public NIC, 10.0.0.1 the IP inside the private network). In the central lighttpd.conf I first define a default server binding to both IPs:

server.bind = "1.2.3.4"                 # public default server
server.port = 80
$SERVER["socket"] == "10.0.0.1:80" {}   # private default server

The vhosts are set up in separate files under conf-enabled/, say vhost1.conf, vhost2.conf etc. I tried to split the following directives across the config files:

## This is for machine2machine communication on port 81 over the Internet
$SERVER["socket"] == "1.2.3.4:81" {
...
}
## This is for machine2machine communication on port 81 inside the private net
else $SERVER["socket"] == "10.0.0.1:81" {
...
}
## This is vhost 1, accessible through Internet and private network
else $HTTP["host"] =~ "^vhost1.do.main$" {
...
}
## This is vhost 2
else $HTTP["host"] =~ "^vhost2.do.main$" {
...
}

and so on. Everything works so far if I put it all in one big config file. But when I split the config into separate files, it seems that the else gives syntax errors since it is not honored across the included cfg files.

While the else would be redundant between the vhosts sections triggered by the HTTP Host header, it is not so in relation to the $SERVER["socket"] section. If I would remove the else, it would be possible to access all vhosts through port 81, inheriting the setup for the m2m host in addition to the ones for named vhosts.

Furthermore, I could not figure out how to define the section for m2m comm in only one block with two $SERVER["socket"] directives for two IPs, so I had to duplicate the setup for the same vhost bound to port 81. If there is a way to combine two $SERVER["socket"] directives for a single section, I could use the default server for port 81 and surround the named vhosts with a $SERVER["socket"] directive binding to port 80.

So my questions are:

  1. Is there a trick I didn't see in the docs to accomplish such a vhost setup with separate cfg files resulting in the same effect as using else?
  2. Can two $SERVER["socket"] directives be combined to avoid having to duplicate the same vhost twice and to encapsulate a bunch of named vhosts, thus avoiding the need for the else? I tested with the || operator, but that didn't work.

Any ideas?

LBC
  • 91
  • 1
  • 1
  • 6
  • Every file has to be syntactically correct. What you can always do is to concatenate a directory and files and use this one. After every change to one of the source files do `cat vhosts-conf/* > conf-enabled/vhosts.conf`. And you can also always imitate a logical or with `conf1 { include common.conf } cond2 { include common.conf }`. – sebix Sep 10 '15 at 17:59
  • Sebix, thank you for your answer. The suggestion with the `include`s is very helpful to merge the port 81 config blocks into a single block. Also concatenation of single configs is a good idea; I probably will integrate this in lighttpd's perl script parsing the config directory. Thanks again! – LBC Sep 11 '15 at 18:15

0 Answers0