Forum

reverse proxy certain file types.

Sjir Bagmeijer
4 January 2016, 14:58
Is there a way to reverse proxy only certain file types?

I am trying to do the following:
VirtualHost {
Hostname = chat.ulyaoth.net
WebsiteRoot = /srv/ulyaoth/public
AccessLogfile = /var/log/hiawatha/ulyaoth-access.log
ErrorLogfile = /var/log/hiawatha/ulyaoth-error.log
StartFile = chat.pl
ExecuteCGI = yes
RequireTLS = yes,31104000
RandomHeader = 512
ReverseProxy ^/register http://127.0.0.1:3000
ReverseProxy ^/login http://127.0.0.1:3000
ReverseProxy ^/lostpassword http://127.0.0.1:3000
ReverseProxy .pl http://127.0.0.1:3000
}


The one i cannot get to work is:
ReverseProxy .pl http://127.0.0.1:3000


I basically want all files with the extension .pl do the reverse proxy but anything else should be done by Hiawatha as usual.

is this possible?
Sjir Bagmeijer
4 January 2016, 16:57
I have to add that the .pl files do not exist in the hiawatha public folder.

So basically I need all requests towards "chat.pl" to go to http://127.0.0.1:3000.
Hugo Leisink
4 January 2016, 22:33
Try ReverseProxy .*\.pl http://127.0.0.1:3000
Sjir Bagmeijer
8 January 2016, 22:43
seems not to work also I think problem is actually on the backend part.

I run a perl program that is build in Mojolicious http://mojolicious.org
[root@chat ~]# curl -I http://127.0.0.1:3000
HTTP/1.1 200 OK
Server: Mojolicious (Perl)


So I guess the problem is that the first request "chat.pl" can't actually be sent to the backend because "http://127.0.0.1:3000/chat.pl" does not work.
it works all fine if I reverse proxy / to the app but due to some legacy I have to run some old .cgi scripts also by Hiawatha.

So to think of it I guess what I really need is the other way around all traffic except ".cgi" files should go to the reverse proxy.
so Hiawatha should handle the cgi files, is such a thing even possible?

or alternative I could run the perl script directly in Hiawatha without the mojolicious servers if I can fix the urls somehow, if i run it in Hiawatha it does this when I click a link: http://127.0.0.1/chat.pl/login but it should do http://127.0.0.1/login (but it has to be run by chat.pl).

Do you have any idea perhaps for one of the two?
Hugo Leisink
9 January 2016, 07:43
Try the following rule to proxy everything but .cgi:
ReverseProxy !\.cgi http://127.0.0.1:3000/chat.pl


To run it via Hiawatha, use this:
CGIhandler = /usr/bin/perl:pl

VirtualHost {
...
EnablePathInfo = yes
ExecuteCGI = yes
UseToolkit = mojolicious
}

UrlToolkit {
ToolkitID = mojolicious
RequestURI exists Return
Match ^(/.*) Rewrite /chat.pl$1
}
Sjir Bagmeijer
9 January 2016, 09:39
Both options work! thank you so much

I will stick with the second one seems to me no point to run another webserver if Hiawatha can handle it with a toolkit.
This topic has been closed.