Odd redirection with proxy external app

18 views
Skip to first unread message

Pedro Pinheiro

unread,
Aug 4, 2017, 11:57:26 PM8/4/17
to OpenLiteSpeed Development
Hi all,

Actually, it's a damn simple problem, yet very very annoying. Let's say I have a local node.js application running on port 7001 and I want all traffic in context /ocs/ to go to localhost:7001 (it's HTTP, not FCGI or something). So, I did something like this:

extprocessor test {
  type                    proxy
  address                 http://localhost:7001
  maxConns                20
  initTimeout             30
  retryTimeout            20
  respBuffer              0
}

context /ocs/ {
  type                    proxy
  handler                 test
  addDefaultCharset       off
}


Problem is... It works, but not the way I expect. When I go to http://server.example.org/ocs/, it sends to the external application a request to http://localhost:7001/ocs... But I needed all requests made to /ocs/ to be redirected to the external web server root. The way it works now, it just translates the URL to an internal server.

Is it possible to workarround it?

Thanks,
-trp

Pedro Pinheiro

unread,
Aug 5, 2017, 12:52:18 AM8/5/17
to openlitespee...@googlegroups.com
Nevermind, just bodged a bit... Took some inspiration here, here and, to a far less extent, here.

So, I created a rewrite rule using Proxy flag, so it went like this:
RewriteRule   "^/ocs(?:\/)?(.*)?"  http://teste/$1  [P,L]

Then, I combined it with other three rules because I needed it to work only with HTTPS.

RewriteCond "%{SERVER_PORT}" ^443$
RewriteRule   "^/ocs(?:\/)?(.*)?"  http://teste/$1  [P,L]

RewriteCond "%{SERVER_PROTOCOL}" "!^HTTPS$"
RewriteRule   "^/ocs(?:\/)?(.*)?"  "https://server.example.org/ocs/$1"  [R,L]

Only a trivia, tho...

Thanks,
Att.,
-trp

P.S.: I'm really sorry about my English, today... I got a little sleepy and tired today trying to get the server to run the way I wanted it to...
Reply all
Reply to author
Forward
0 new messages