Feb 12 2010
Nginx Rocks at Proxying
I was pushing out the magnolia-railo-demo and was looking at the site performance. It was amazing by itself, sending back magnolia-railo built pages in 100ms including wire time from Portland to Dallas raw from Tomcat. On this box I have one IP though and I wanted to use a subdomain for the demo which means proxying vhosts.
When I proxied it through Apache’s httpd it took about twice as long for the page to load! (roughly 130-150ms for the base page) It seemed totally ridiculous… Now in all fairness I’m no Apache expert, but I decided to drop in nginx as a proxy on the front end and its cost as a proxy is nearly unnoticeable. I wouldn’t be able to tell it apart from hitting tomcat directly as far as speed is concerned.
I’ll have to give this a closer look for my other projects…
One slightly tricky thing is that if you need Apache’s ProxyPreserveHost in Nginx you need to use proxy_set_header Host like this:
location / {
root /usr/share/nginx/html;
index index.html index.htm;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:80;
}
Sometimes I wonder what it will be like when apache’s gone. I will probably find myself cding into /etc/httpd/logs and cat access_log over and over… just to remember old times.