Project

General

Profile

Regex assistance sought. $HTTP["host"] domain match, ignore anything matching on "mydomain.com/ENDPOINTS"

Added by bengtssondd over 5 years ago

Hi there....

I'm trying to setup Lighttpd to match on:

$HTTP["host"] == "bengtssondd.it" {

ONLY....so no:

bengtssondd.it/myLighttpdWebfolder, bengtssondd.it/myOtherLighttpdWebfolder and so on.
- If the match is not on bengtssondd.it only Lighttpd should just handle the request like any other request and see if there is a matching folder ind the default webroot path.

How would I attack that?

I've tried:
- Searching on this forum for $HTTP["host"]. Lots of results, however, after 6 search result pages I stopped looking for more.
- Tried various ways of matching. All I'm able to do is get either bengtssondd.it to work bengtssondd.it/myLighttpdWebfolder not both at the same time.
- Read: https://redmine.lighttpd.net/projects/1/wiki/docs_configuration, https://www.regular-expressions.info/lookaround.html, https://jsebean.com/2017/11/lighttpd-regex-rewrites-and-you and https://blog.evanweaver.com/2006/06/07/regular-expressions-in-lighttpd-host-redirects/

I hope someone in here can give me a hint or two and thereby push me in the right direction.


General info:
- Lighttpd v1.4.48
- Busybox distro. On a QNAP. Using Entware as the installation mechanism.
-- Kernel is v4.2.8
- HAProxy is in front of lighttpd. Mathing on.

        # Bengtssondd.it website config
        acl bengtssondd hdr_beg(host) -i bengtssondd.it
        use_backend lighttpd_back if bengtssondd

and

        acl mediawiki path_beg /mediawiki
        use_backend lighttpd_back if mediawiki

the backend looks like

backend lighttpd_back
        redirect scheme https if !{ ssl_fc }
        server localhost_lighttpd 127.0.0.1:8888 check

- I've been using Firefox as well as Chrome to control success or not on each regex change.

Thank you so much.


Replies (4)

RE: Regex assistance sought. $HTTP["host"] domain match, ignore anything matching on "mydomain.com/ENDPOINTS" - Added by gstrauss over 5 years ago

server.document-root = "/path/a" 

$HTTP["host"] == "bengtssondd.it" {
  server.document-root = "/path/b" 
}

lighttpd 1.4.46 and later support the HAProxy PROXY protocol. See Docs_ModExtForward and extforward.hap-PROXY = "enable"

RE: Regex assistance sought. $HTTP["host"] domain match, ignore anything matching on "mydomain.com/ENDPOINTS" - Added by bengtssondd over 5 years ago

Hi @gstrauss,

Thank you for your response.

From your comments I've tried:

  1. Experimented with an extra
    server.document-root
    . That did not make it work. Rather the opposite.
    1. There is already a
      server.document-root
      besides the one in the
      $HTTP["host"]....
      catch.
  2. Enabled the ModExtForward module. And specifically for HAProxy. That made no change.

I think I need a little more guidance. Specifics. As I get a couple of questions from your response.

  • Should enabling the ModExtForward module help me get to the goal?
  • Can one have:
    $HTTP["url"]...
    
    clauses nested in the
    $HTTP["host"]
    
    ... clause?

Specifically, just so that we are on the same page. I'm trying to make the following work:

  1. I can have a:
    $HTTP["host"] == "bengtssondd.it" {...
  2. Outside that a:
    server.document-root = "/basePathTo/wwwroot"
  3. Only requests to the root-domain
    bengtssondd.it
    should go inside:
    $HTTP["host"] == "bengtssondd.it" {...
    1. All other requests should go-to
      server.document-root = "/basePathTo/wwwroot/matchingSubfolder"

Thank you very much.

RE: Regex assistance sought. $HTTP["host"] domain match, ignore anything matching on "mydomain.com/ENDPOINTS" - Added by gstrauss over 5 years ago

Specifics: if you can't get the 4-line solution to work, then you should get that working before you continue. It really is that simple in lighttpd.

Get something SIMPLE working. Simple means bare-bones. No HAProxy. No anything else.

Get a simple solution working. Then start adding your features/complexity back one step at a time, testing between each change.

RE: Regex assistance sought. $HTTP["host"] domain match, ignore anything matching on "mydomain.com/ENDPOINTS" - Added by bengtssondd over 5 years ago

Hi @gstrauss,

Again, thank you for replying.

Looked into it again. This time without HAProxy in front of Lighttpd. And with Lighttpd running on port 80. Still can't get it to work.

Will doing:

$HTTP["host"] == "bengtssondd.it" {...

not clash with:

an URI that is bengtssondd.it/XWebsiteEndpoint

????

I'm asking as I can't see how the $HTTP["host"] conditional configuration will allow for the server.documen-root to be different for requests to the "flat" domain - bengtssondd.it in this case. And bengtssondd.it/XWebsiteEndpoint

I've read > https://redmine.lighttpd.net/projects/lighttpd/wiki/Server_document-rootDetails

Thanx

    (1-4/4)