1

I currently have a few hundred web applications spread across around 20 servers, and a reverse proxy sat in front of these running Pound and Haproxy. Pound is doing the http to https redirect and SSL encryption and then forwarding on to Haproxy which has a rule set up for each site to forward to one of the backend servers running Tomcat. All sites are on the same domain eg www.domain.com/webapp1, www.domain.com/webapp2

Pound and Haproxy were originally setup by our hosting provider, and having grown frustrated with Pound I'm now looking at replacing this setup with Nginx. I'm at a point where I've got Nginx running in a dev environment doing the https redirect and SSL, and I have a couple of rules setup to proxy to a backend.

I'm really just after some advice on whether this is the best way to go about this, or if I'd be better off leaving Haproxy handling all the rules and just configuring Nginx as a replacement for Pound.

My worry is that I'll configure Nginx with the hundreds of forward rules like below and end up with performance issues. Any suggestions would be welcome, thanks.

location /webapp1/ {
     proxy_pass http://10.1.9.11:8080;
}

location /webapp2/ {
     proxy_pass http://10.1.9.11:8080;
}

location /webapp3/ {
     proxy_pass http://10.1.9.12:8080;
}
1

I do no know much about haproxy but I know enough about nginx to answer your worries with performance issues.

Note that nginx configuration is compiled into a struct friendly format and kept in memory, the file is not read on each request. Therefore, hundreds of location /... configurations shall run almost as fast as calling strlen() + strncmp() the same number of times. Which is negligible compared to socket setup.

The URL is normalised before the matching begins therefore there is nothing really clever about the matches unless you use one of the operators (=, ~, *~, ^~).

You could use a regex match (~, *~) and then some if logic to decide between the upstream servers but that would be the slow solution.

On the other hand, if you do have at least one regex location then you shall consider using the ^~ operator. See the old but still relevant answer by Martin Redmond on SO about different operators and how nginx matches them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.