Project

General

Profile

[Solved] How to use strip-request-uri in mod_proxy in 1.4.45

Added by brianddk over 5 years ago

I'm trying to redirect requests from http://myhost.tld:1234/proxy?query=data to http://localhost:4321/proxy using mod_proxy. My hope was to strip off the ?query=data in the process

server.modules = (
        "mod_alias",
        "mod_redirect",
        "mod_proxy",
)

$SERVER["socket"] == ":1234" {
  $HTTP["url"] =~ "^/proxy" {
    proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "4321", "strip-request-uri" => "/proxy" ) ) )
  }
}

But that that doesn't seem to strip anything. What I see on my localhost:4321 service is the following request, which doesn't seem to be stripped

GET /proxy?query=data HTTP/1.0
Host: myhost.tld:1234
User-Agent: curl/7.58.0
Accept: */*
X-Forwarded-For: 15.16.17.18
X-Host: myhost.tld:1234
X-Forwarded-Proto: http

Question

  1. Is my syntax for strip-request-uri correct in this context?
  2. Should I instead try to nest mod_rewrite and mod_proxy together somehow... Is that possible?

Answers

  1. Nope... use mod_rewrite with v1.4.50 instead
  2. Yes... moving to v1.4.50 makes it even easier

Working config

server.modules = (
        "mod_alias",
        "mod_redirect",
        "mod_proxy",
        "mod_rewrite",
)

$SERVER["socket"] == ":1234" {
  $HTTP["url"] =~ "^/proxy" {
    url.rewrite-once = ("^/(.*)" => "${url.path}")
    proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "4321" ) ) )
  }
}

SysInfo

  • Ubuntu 18.04.1 LTS (Bionic Beaver)
  • Kernel 4.15.0-1021-gcp x86_64 (packaged with bionic)
  • lighttpd 1.4.45-1ubuntu3 bionic in /usr/sbin
  • Client: curl/7.58.0

Replies (2)

RE: [Solved] How to use strip-request-uri in mod_proxy in 1.4.45 - Added by gstrauss over 5 years ago

It is usually preferable to list "mod_rewrite" prior to "mod_proxy" in the server.modules list.

    (1-2/2)