For the longest time, we’ve been using the native tomcat connectors to link our web servers to our Tomcat or Jboss Application servers. The connectors are modules that plug in to IIS or Apache and provide a link from one to the other. The main driver to use such a structure was to take advantage of the webservers’s easier Virtual Host and HTTPS configuration  and to serve static pages or other sites.  To be frank, it’s always been a pain. When we discovered the Nginx project, we realised that all that pain was about to go away.

Nginx is an http server and reverse proxy designed to be fast and easy to configure. The Nginx.org site boasts that that 43 million sites now run the web server, so we felt that it was probably stable enough for our uses!

Rather than configuring system to use the AJP13 connector, nginx proxies to the Tomcat/Jboss web server (normally running on 8080). The configuration is a simple as this:

location /application {
proxy_pass        http://www.firstoptionsoftware.com:8080;
}

Send any traffic with the /application path to localhost on port 8080. Https configuration is similar to Apache in it’s style, as are virtual hosts. One benefit of this simplicity is that the the web server can redirect to different backend servers based on directory such as:

server {
listen www.example.com;
location /application {
proxy_pass        http://www.firstoptionsoftware.com:8080;
}

location /internal_application {
proxy_pass        http://internalserver:8080;
}
}

Browsing http://www.example.com/application would pass traffic to an application server on the local machine, whereas http://www.example.com/internal_application would sent the traffic to a second server for processing. As Nginx is acting as a proxy there is no direct access to the internal system, the access only occurs for a specific path and the client is only aware of one server – www.example.com. Useful for portals or intranets where information can be brought together on one site. For https connections, the Nginx server acts as an SSL off loader leaving the application servers to do what they need without the extra load of encryption or complication in load-balancing situations.

Finally, files can be served from the filesystem, separating dynamic content from static allowing for better cacheing.

location /application {
proxy_pass        http://www.firstoptionsoftware.com:8080;
}

location /images/  {
root    /var/www/htdoc/images;
expires 15d;
}

Our experience is that Nginx simplifies the deployment process without sacrificing  speed or features that we need in our websites.

http://nginx.org