0

I'm running lighttpd 1.4.33, which is reverse proxied to from an Apache server that is open to the Internet. When accessing a script from the local address of the lighttpd server, GET parameters are passed to the script just fine, and I get the expected result. However, when the script is accessed through the proxy (and is rewritten by the following lighttpd rule), the query parameters seem to be dropped completely.

The rewrite rule that seems to be causing the problem:

$HTTP["host"] =~ "^site\.example\.com$" {
        # This affects the requests that aren't rewritten below, ie. static stuff
        server.document-root = "/var/www/example/public"   
        url.rewrite-once = ( "^((?!assets).)*$" => "index.php/$1" )
}

Which is supposed to rewrite all URLs so they are passed through the routing engine in index.php, except the static stuff in the /assets directory, which should just be served statically. Note that /assets is a subdir of /var/www/example/public, so this works correctly.

Lighttpd debug log for the request with the dropped parameter:

2014-07-23 11:36:46: (response.c.310) Request-URI  :  /foo/bar?someparam=data 
2014-07-23 11:36:46: (response.c.311) URI-scheme   :  http 
2014-07-23 11:36:46: (response.c.312) URI-authority:  site.example.com 
2014-07-23 11:36:46: (response.c.313) URI-path     :  /foo/bar 
2014-07-23 11:36:46: (response.c.314) URI-query    :  someparam=data 
2014-07-23 11:36:46: (response.c.309) -- splitting Request-URI 
2014-07-23 11:36:46: (response.c.310) Request-URI  :  index.php/a
2014-07-23 11:36:46: (response.c.311) URI-scheme   :  http 
2014-07-23 11:36:46: (response.c.312) URI-authority:  site.example.com 
2014-07-23 11:36:46: (response.c.313) URI-path     :  index.php/a 
2014-07-23 11:36:46: (response.c.314) URI-query    :

Note the blank URI-query field on the last line. It seems as though the step "splitting the request URI" is breaking everything.

Any ideas on what could be causing this?

1 Answer 1

1

It turns out that there is a simpler way to do this on lighttpd >= 1.4.24. You can use the url.rewrite-if-not-file directive, like so (lighttpd <= 1.4.33):

$HTTP["host"] =~ "^site\.example\.com$" {
        # Rewrite all requests to non-physical files
        url.rewrite-if-not-file =
        (
            "^(.*)$" => "index.php/$1"
        )
}

That example uses the $HTTP["host"] directive, as using the $HTTP["url"] directive was unsupported up until 1.4.34. In lighttpd >= 1.4.34, you can use it in a URL conditional block:

$HTTP["url"] =~ "^\/site/$" {
        # Rewrite all requests to non-physical files
        url.rewrite-if-not-file =
        (
            "^(.*)$" => "index.php/$1"
        )
}

I guess if you're well and truly forced to use lighttpd <= 1.4.24, you can always use mod_magnet and Lua.

1
  • $HTTP["url"] never includes the hostname.
    – Stefan
    Jul 24, 2014 at 17:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .