unit
unit copied to clipboard
Multiple proxy doesn't work
Unit version 1.27.0
{
"listeners": {
"*:80": {
"pass": "routes"
},
"*:443": {
"pass": "routes",
"tls": {
"certificate": [
"testbundle"
]
}
}
},
"routes": [
{
"match": {
"uri": [
"!/index.php",
"!/test/*",
"!/lala/*"
]
},
"action": {
"share": "/var/www/laravel/public$uri",
"fallback": {
"pass": "applications/laravel"
}
}
},
{
"match": {
"uri": "/test/*"
},
"action": {
"proxy": "http://127.0.0.1:8000"
}
},
{
"match": {
"uri": "/lala/*"
},
"action": {
"proxy": "http://127.0.0.1:80"
}
}
],
"applications": {
"laravel": {
"type": "php",
"root": "/var/www/laravel/public/",
"script": "index.php"
}
}
}
I have configuration file like this. But I get problem with it. I tried to set paths to use proxy to any application. Expecting: :80 - laravel :80/api - application 2 :80/test - wordpress
Result

I haven't idea why redirect didn't work
Hi @Pavlusha311245 thanks for reaching out.
As all of your applications are PHP-based, why did you not run all the applications on Unit and use the application
object to route traffic to your applications.
Anyhow, please note that rewrites are currently not a thing in Unit. That means if you want to use location based routes for different applications, the application has to be aware of it.
Wordpress for example need to be configured to use /test/
as your home location instead of /
. Otherwise you would the the 301 redirect.
I will check the configuration and let you know my findings.
I can't use only PHP application, beacause other ones started on docker
Hi @Pavlusha311245 I have looked at your configuration and created a smal test on my side using the following configuration
{
"listeners": {
"*:80": {
"pass": "routes"
}
},
"routes": [
{"match": {"uri": "!/test/*"}, "action": {"return": 413}},
{"match": {"uri": "/test/*"}, "action": {"proxy": "http://127.0.0.1:8000"}}
],
"applications": {}
}
The backend for port 8000
is a simple Python HTTP Server started with python3 -m http.server 8000
. This configuration works for me and I can reach my Python backend issuing curl localhost/test/
.
That said, the proxy configuration itself is correct. I assume the problem is based on your WP configuration. As already mentioned, if wordpress is NOT configured to be hosted with a location like /test/
it will redirect the request to /
.
Can you share the output of curl -v http://localhost/test/
?
One last thing. Your /lala/
location will create a loop.
{
"match": {
"uri": "/lala/*"
},
"action": {
"proxy": "http://127.0.0.1:80"
}
}
as you are proxying back to Unit and Unit will find /lala/
in its routes again it will end up in an request loop and that will end up in running out of available file descriptors after some time.
Hi @Pavlusha311245 I have looked at your configuration and created a smal test on my side using the following configuration
{ "listeners": { "*:80": { "pass": "routes" } }, "routes": [ {"match": {"uri": "!/test/*"}, "action": {"return": 413}}, {"match": {"uri": "/test/*"}, "action": {"proxy": "http://127.0.0.1:8000"}} ], "applications": {} }
The backend for port
8000
is a simple Python HTTP Server started withpython3 -m http.server 8000
. This configuration works for me and I can reach my Python backend issuingcurl localhost/test/
.That said, the proxy configuration itself is correct. I assume the problem is based on your WP configuration. As already mentioned, if wordpress is NOT configured to be hosted with a location like
/test/
it will redirect the request to/
.Can you share the output of
curl -v http://localhost/test/
?One last thing. Your
/lala/
location will create a loop.{ "match": { "uri": "/lala/*" }, "action": { "proxy": "http://127.0.0.1:80" } }
as you are proxying back to Unit and Unit will find
/lala/
in its routes again it will end up in an request loop and that will end up in running out of available file descriptors after some time.
I will try
Any update on this @Pavlusha311245