Forum

Alias vs ReverseProxy

Mike
26 March 2018, 04:16
I've been trying to get this nginx config translated to Hiawatha with no success. It seems that the reverse proxy overrides the alias;
nginx config:
server {
listen 8080;
server_name localhost;
access_log off;

location /static/ {
alias /opt/app/app/static/;
}

location / {
proxy_pass http://app:8001;
}
}
}

Hiawatha config:
VirtualHost {
set THIS = mydomain
Hostname = THIS
WebsiteRoot = /var/www/THIS
RequiredBinding = http, https
...
Alias = /static:/opt/app/app/static
ReverseProxy = ^/app/ http://app:8001
}

Thanks
Hugo Leisink
26 March 2018, 17:47
Yes, an alias points to a file on disk. You don't want to do this before forwarding it to another webserver, as that file on disk might be placed outside the webroot. The aliassing should be done at the backend webserver.

I doubt that the nginx configuration works differently.
Mike
26 March 2018, 21:12
Indeed the nginx config works the opposite way. Everything that points to /static gets served out of /opt/app/app/static/ and anything else get's served out of the backend server.

Is the <pattern> syntax documented anywhere, I tried to do a negative lookahead to block redirecting anything that goes to /app/static but it was rejected? Same with the precedence order of alias, reverseproxy, urltoolkit, etc?
Hugo Leisink
27 March 2018, 12:45
The <pattern> is a regular expression. If you know regular expressions, it says enough. If you don't, learn about regular expressions.

The order is not documented, but it is URL toolkit, reverse proxy, alias.
Mike
27 March 2018, 20:45
Unfortunately that is not the case , the valid regex I use for ReverseProxy <pattern> is rejected by hiawatha:

ReverseProxy ^/app/(?!static/).*$ http://app:8001
or
ReverseProxy ^\/app\/(?!static\/).*$ http://app:8001

are both rejected with: Syntax error in hiawatha.conf on line 191.

You can check the regexes against any online tester and see they are perfectly valid:
https://www.regexpal.com/?fam=102956
Mike
27 March 2018, 21:29
Also I looked at this post from 2015: https://www.hiawatha-webserver.org/forum/topic/1924/#10018 and there you said reverse proxy selection comes before URL toolkit. So which one it is? URLToolkit > ReverseProxy > Alias or ReverseProxy > URLToolkik > Alias?
Mike
28 March 2018, 00:42
Digging a bit deeper, it seems that the regex dialect you are using is very minimal/barebones. Can I add a +1 to the request to implement a more robust regex library (http://www.pcre.org/). The work done by the sljit (http://sljit.sourceforge.net/) guys might be interesting to add too so you end up with "PCRE-sljit". That will open a whole lot of possibilities. for the <patthern> that Hiawatha can support.
PCRE have a posix compatible wrapper so the integration effort should be lower too!
Mike
28 March 2018, 04:42
Alternatively, if PCRE is not going to happen, can you add somewhere in the documentation that Hiawatha only supports POSIX ERE. The phrase regular expressions is not accurate enough to convey what can and can't be done with Hiawatha.
Hugo Leisink
31 March 2018, 15:07
I'll put PCRE on my to-take-a-look-at list. But if you really need advanced and complex regular expressions, you also might wonder what your doing. I truly believe that the only rewriting a web server should do is rewrite URLs to non-existing files to a default CGI script, like /index.php. All other rewriting should very likely be part of the web application.
Mike
10 April 2018, 00:42
Thanks for the answer Hugo! As I mentioned in another post, what I'm trying to do is replace an nginx setup with Hiawatha.

Due to the priority order of operation in Hiawatha, the only way I can think of to accomplish this is using a negative look-ahead <pattern> in the ReverseProxy configuration to avoid forwarding requests to a specific path and serve those directly (all static assets).

Unfortunately, I can't modify the application in any way.
Allowed BBcodes:
[quote]
[code]
[config]
[url]
[color]
[size]
[img]
[b]
[i]
[u]
[s]
[list]
[ul]
[ol]
[*]