I'm trying to configure lighttpd to proxy traffic to one relative path to one proxy server, and traffic to another path to another proxy server.
For example:
http://mydomain.com/ proxies to 123.111.111.1
http://mydomain.com/apathname/ proxies to 123.111.111.2
I am flumoxed trying to figure out how to the the /apathname/ configured. This is a sample of what I have configured so far, which just directs all traffic to 123.111.111.1
$HTTP["host"] =~ "mydomain.com" {
proxy.balance = "fair"
proxy.server = (
"" =>
(
("host" => "123.111.111.1", "port" => "80" )
),
"apathname" =>
(
( "host" => "123.111.111.2", "port" => "80" )
)
)
}
My apologies if this question should be on another SO site. I'm primarily a coder, not a network guy, and I know I always get the best answers on SO itself, which is why I'm asking here.
You need to check the request URL from $HTTP["url"] and set up multiple proxy rules, like this:
$HTTP["host"] =~ "(www.example.com)" {
server.document-root = "/var/www/www.example.com"
$HTTP["url"] =~ "^/upload(.*)$" {
proxy.server = ("" => (
("host" => "10.2.2.1", "port" => 3000)
))
}
$HTTP["url"] =~ "^/submit(.*)$" {
proxy.server = ("" => (
("host" => "10.2.2.2", "port" => 3000)
))
}
}
In this example above:
everything requested from /upload will be proxied to 10.2.2.1:3000.
everything requested from /submit will be proxied to 10.2.2.2:3000.
Related
I've a Lighttpd server running on HTTPS, and I want to have one subdirectory on the server act as a reverse proxy for a separate server that runs on HTTP. I've tried following guides on doing both proxy and url rewrite, but something to do with how the SSL is set up is interfering.
$SERVER["socket"] == ":81" {
url.rewrite-once = ( "^/directory/(.*)$" => "/index.html" )
proxy.server = ( "" => ( "" => ( "host" => "192.0.0.1", "port" => 123 )))
}
$HTTP["scheme"] == "http" {
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
}
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.ca-file = "/etc/lighttpd/fullchain.pem"
ssl.pemfile = "/etc/lighttpd/server.pem"
$HTTP["url"] =~ "^/directory/" {
proxy.server = ( "" => ( "" => ( "host" => "127.0.0.1", "port" => 81)))
}
}
My intention was that going to /directory/ would redirect you to the 192.0.0.1:123/index.html. I followed this guide which mentioned doing the first redirect to port 81, then redirecting port 81 to the second server.
This doesn't seem to work and just gets stuck in a redirection loop, and always returns a 301 to the https site.
If I don't do the :81 redirect, I can get the bottom proxy.server to redirect to the right place, but it keeps the /directory/ ending which doesn't get to where I need it.
Thanks.
Since lighttpd 1.4.46, mod_proxy can rewrite url-prefixes.
$HTTP["scheme"] == "http" {
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
}
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.ca-file = "/etc/lighttpd/fullchain.pem"
ssl.pemfile = "/etc/lighttpd/server.pem"
$HTTP["url"] =~ "^/directory/" {
url.rewrite-once = ( "^/directory/(.*)$" => "/directory/index.html" )
proxy.header = ( "map-urlpath" => ("/directory/" => "/") )
proxy.server = ( "" => ( "" => ( "host" => "192.0.0.1", "port" => 123)))
}
}
I have this internal site (192.168.2.1) which is only accessible with http
On a different server I run a public web-server using lighttpd. I can make this internal site accessible to the outside work as follows
$HTTP["host"] == "internal.example.com" {
...
proxy.server = ( "" =>
( "internal" =>
(
"host" => "192.168.2.1",
"port" => 8000
)
)
}
This works, but I would like to use https for the outside world. So my question is, how can I proxy this going from https to http ?
I've tried something like this:
$SERVER["socket"] == ":443" {
$HTTP["host"] == "internal.example.com" {
...
proxy.server = ( "" =>
( "internal" =>
(
"host" => "http://192.168.2.1",
"port" => 8000
)
)
}
}
But this doesn't seem to work. Any help would be appreciated
UPDATE: I get the impression that https is not supported in combination with reverse proxies. Maybe HAProxy is the solution
lighttpd can listen to clients on https and proxy to a backend via http.
In your config example, is the external client sending requests to https://internal.example.com/... ? The authority (e.g. hostname) of the external URL is what needs to go into your $HTTP["host"] condition which enables the proxy.
$SERVER["socket"] == ":443" {
$HTTP["host"] == "external.example.com" {
...
proxy.server = ( "" =>
( "internal" =>
(
"host" => "192.168.2.1",
"port" => 8000
)
)
)
}
}
I have a lighttpd webserver running simple vhosts. I would like to do an url rewrite for just one of the hosts. I tried this in /etc/lighttpd/lighttpd.conf:
$HTTP["host"] == "api.sitename.com" {
server.document-root = "/var/www/api.sitename.com/"
accesslog.filename = "/var/log/lighttpd/api.sitename.access.log"
url.rewrite = ( "^(.*)$" => "/index.php?$1" )
}
For use with an API. (https://github.com/alixaxel/ArrestDB)
url.rewrite = ( "^(.*)$" => "/index.php/$1" )
change : ^
from ? to /
I would like redirect addresses that start with:
en.example.com/somefile.php
to:
example.com/somefile.php?language=en
Using mod_rewrite module in lighttpd. Until now I got this:
$HTTP["host"] =~ "^en\.(.*)\.com$" {
url.rewrite-once = (
"^/(.*)"
=>
"/$1?language=en"
)
}
But this does not seem to be working. What to do to make this work?
Try this:
$HTTP["host"] =~ "^en\.([^/.]+)\.com$" {
url.rewrite-once = (
"^/([^?]*)(\?(.*))?" => "http://%1/$1?language=en&$3"
)
}
Try this
$HTTP["host"] !~ "^(en|fr)\.([^.]+\.com)$ {
url.rewrite-once = (
"^/(.*)" => "http://%2/$1&language=%1"
)
}
This should rewrite subdomains en. and/or fr. to whatever domain (including the TLD) with the URL string intact, and append the language parameter.
Examples:
http://en.example.com -> http://example.com/&language=en
http://fr.example.com/directory/ -> http://example.com/directory/&language=fr
try following.. if it works for you..
$HTTP["host"] =~ "^en.([^.]+.com[a-z0-9-]+.php)$" {
url.rewrite-once = (
"^/(.*)"
=>
"/$1?language=en"
)
}
I currently have a proxy.server rule in lighttpd.conf that forwards all requests of routemsg.pl to port 1530:
$HTTP["url"] =~ "/routemsg.pl" {
proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 1528) ) )
}
How can I change the rule to allow the requester to pass a port param in the URL and that param be then used as the port to proxy the request to?
For example: A request of: http://www.myip.com/routemsg.pl?p=1531 would go to 127.0.0.1 on port 1531.
You could try using $HTTP["querystring"] and capture the port with a conditional like this:
$HTTP["url"] =~ "/routemsg.pl" {
$HTTP["querystring"] =~ "p=([0-9]+)" {
proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => "%1") ) )
}
}
I sadly don't have a setup on which I can confirm that it works right now, I'm afraid. :(