Project

General

Profile

[Solved] Multiple address binding in a $SERVER block

Added by Anonymous about 2 months ago

I have a significant configuration inside of a $SERVER{} block. I want to bind it to two addresses, loopback, and a private LAN IP. I can't figure out how to do this without duplicating the entire configuration within the $SERVER{} block for each. I would just do this, but I'm concerned this will duplicate resource usage and this is all running on a router.

Is there a way to specify multiple bind addresses in a $SERVER block?


Replies (4)

RE: Multiple address binding in a $SERVER block - Added by gstrauss about 2 months ago

I would just do this, but I'm concerned this will duplicate resource usage and this is all running on a router.

Did you test anything or are you guessing? It's not a problem unless you test it and demonstrate it is a problem. Hint: it's probably not a problem. You're wasting everyone's time by failing to test your hypothesis.

I can't figure out how to do this without duplicating the entire configuration within the $SERVER{} block for each.

One option is to put all of that in the global config, and then have lighttpd bind to loopback and your private LAN IP.
server.port = 80 # default
server.bind = 127.0.0.1
$SERVER["socket"] "127.0.0.1:80" { } # redundant with server.bind above and default server.port
$SERVER["socket"] "192.168.1.1:80" { }

Another option is to put all your config into an include file that is included in each $SERVER["socket"] block where it is needed. The first option is more efficient and does not duplicate any config. The second option duplicates some config, but even that is generally efficient in lighttpd, as fastcgi and other backends are deduplicated where possible.

Hint: it's probably not a problem. You're wasting everyone's time by failing to test your hypothesis.

Of course, I'm sure that before posted, you already search the wiki and read
FAQ: How do I bind to more than one address?
so if you did not understand it, please provide feedback how it might be improved.

RE: Multiple address binding in a $SERVER block - Added by Anonymous about 2 months ago

One option is to put all of that in the global config

The configuration in the block is not appropriate for the global config, hence why it's in the block.

Of course, I'm sure that before posted, you already search the wiki and read
FAQ: How do I bind to more than one address?

Indeed, but thank-you. The documentation seems to suggest the only ways to bind multiple addresses is
1) Multiple $SERVER blocks with one address per block or,
2) Specifying a global bind address prior to a $SERVER block

#1 I was trying to avoid as wasteful, and #2 is not appropriate as I do not want to bind that address/port globally.

I also tried 3) Specifying a server.bind address inside the block, thinking that this would naturally add another bind address, but this incurred a warning of being deprecated.

Did you test anything or are you guessing?

The resource usage for the wastefully duplicated configuration wasn't the decision point on whether or not to write this, so no. I would have asked regardless, since I assumed I was just misunderstanding something basically obvious (like a comma separated list of address/ports being accepted in a $SERVER statement) since I couldn't fathom that the configuration for multiple binds is as dumb as it seemed to be. The testing comes now that I realize it really is, and that will be the decision point on whether or not I actually use the duplicated $SERVER block configuration, or live without one of the two bound addresses.

You're wasting everyone's time
You're wasting everyone's time

Clearly.

RE: Multiple address binding in a $SERVER block - Added by gstrauss about 2 months ago

The resource usage for the wastefully duplicated configuration wasn't the decision point on whether or not to write this

Please re-read your original post. Your statement above seems to contradict your original post containing:

I would just do this, but I'm concerned this will duplicate resource usage and this is all running on a router.

The rest of the information you provided in your second post was not provided in your first post.

I don't read minds.

I am competent with basic logic, and lighttpd.conf conditional logic is documented in Configuration: File Syntax

$SERVER["socket"] == "127.0.0.1:80" { }
$SERVER["socket"] == "192.168.1.1:80" { }
$SERVER["socket"] == "1.2.3.4" { # e.g. public IP
  # one set of config
}
else {
  # other, different set of config
}

RE: Multiple address binding in a $SERVER block - Added by gstrauss about 2 months ago

Is there a way to specify multiple bind addresses in a $SERVER block?

No. The documentation does not say that lighttpd does that and lighttpd does not do that. Your fabricated syntax is fabricated.

However, lighttpd does provided multiple documented ways to configure lighttpd listening sockets, and I gave some examples in prior posts. Please see the documentation Configuration: File Syntax

    (1-4/4)