Welcome!

Big Data Journal Authors: Roger Strukhoff, Greg Ness, Elizabeth White, Carmen Gonzalez, Esmeralda Swartz

Related Topics: Virtualization, Java, Linux, Open Source, AJAX & REA, Web 2.0, Big Data Journal

Virtualization: Article

Easily Boost Your Web Application Using nginx

The performance improvement is quite significant for serving static content

More and more Web sites and applications are being moved from Apache to nginx. While Apache is still the number one HTTP server with more than 60% on active Web sites, nginx has now taken over 2nd place in the ranking and relegated Microsoft's IIS to 3rd place. Among the top 10.000 Web sites nginx is already the leader in the field, with a market share of 40%.

And the reasons are obvious: nginx is a high-speed, lightweight HTTP server engine. The performance improvement is quite significant for serving static content. Especially at high load, nginx is much faster than Apache and consumes much less resources on the server. Thus, concurrent requests can be handled more efficiently. As a consequence, the same tasks can be fulfilled by less hardware. And every byte of memory, CPU or even server to be economized reduces your infrastructure costs.

I ran some load tests: 10.000 requests showed quite remarkable differences, even more distinct with more concurrent users. Note that with Apache the total execution time increases with the number of users, while nginx can easily handle that. For 2,000 users, nginx could process the requests almost four times faster.

While nginx uses an event-based request handling in a small number of processes, Apache is spawning new processes or threads for each request, depending on the processing mode. Apache's default multi-process (prefork) mode creates child processes for each request. Such a process is a complete instance of Apache including all linked modules. That means that even a request for static content, like an image, causes a new process to be started and the PHP module to be loaded.

Apache can also be operated in a multi-threaded (worker) mode, which creates multiple threads in fewer processes, one per request. Thus, it consumes much less memory, but the operation is no longer thread-save. Therefore modules like mod_php can't be used.

I went through the exercise of figuring out the best way to leverage nginx on an application that runs on Apache. In this blog we will cover the actual installation steps, different deployment and migration scenarios, as well as how to measure the actual performance gain.

Installing nginx
All you have to do to start boosting your application performance is to install nginx on your machine and follow some configuration rules. In this article I will be referencing an example site running Ubuntu.

sudo apt-get install nginx

No doubt, Apache provides much more functionality by supplying a broad range of mountable modules and many more options to be configured. A common way to adjust the behavior of a website is a combination of the virtual host setup and using the .htaccess file. First of all: this file doesn't exist in nginx, which is another performance bonus. Apache checks every single directory in the path of the requested file for an .htaccess file and evaluates the content if it exists. And, if not configured properly, keeping a config file together with your data could result in a severe security issue. Nginx keeps the configuration in a central place and loads the settings into memory at startup.

Even if you are not sure whether or not you really should replace Apache by nginx, you could always use both together? We will cover this later.

Migrating Configuration
There are quite some similarities, but it's important to understand the differences between the configurations. Just like Apache, nginx keeps the files in /etc/nginx/sites-available. Use a symbolic link for active configurations in /etc/nginx/sites-enabled.

First of all, create a server block for each virtual host.

server {
listen 80;
...
}

The basic setup for running a site is similar to Apache, with a slightly different syntax:

#

# Apache

#

#

# nginx

#

<VirtualHost *:80>

ServerName mysite.com
ServerAlias www.mysite.com

DocumentRoot /srv/www/mysite
DirectoryIndex index.php index.html

</VirtalHost>

server {
listen: 80;

server_name mysite.com www.mysite.com;

root /srv/www/mysite;
index index.php index.html;

}



To add specific behavior for certain requests define a location inside your server block. You can use regular expressions to select the effected requests:

server {
...

location / {
try_files $uri $uri/ @notfound;
}

location /doc/ {

alias /usr/share/doc/;

autoindex on;

allow 127.0.0.1;

deny all;

}

location /images/ {
root /media/images

}

location @notfound {

rewrite (.*) /index.php?paramstring=$1;

}

location ~ /\.ht {

deny all;

}
}

This sample configuration shows some of the setup options for server/locations. Make sure to create a config to deny .ht* files, as nginx is not doing that from scratch. Direct access to these files is automatically rejected by Apache. Note that familiar options from Apache can be found here in nginx: allow/deny, alias, rewrite, etc.

Please refer to the online documentation on nginx.org for further information.

Especially when you have multiple websites running on your server, and lots of requests causing high load, it is a good decision to move to nginx. But multiple websites, configured differently, could result in a quite high effort on migration. There are some converters available doing that job for you, but mainly they convert a .htaccess file to an nginx config. But Apache also uses configurations for virtual hosts - do not forget about these! Even if converted by a tool, I recommend checking your configurations manually before using them in a production environment!

Tip: install nginx as the primary HTTP server and leave your Apache running on a different port. Migrate your virtual servers one-by-one by creating nginx server configurations, and forward requests for not-yet-migrated websites to Apache. I'll show you how:

For my insight into nginx, and a look at Apache, click here for the full article

More Stories By Harald Zeitlhofer

Harald Zeitlhofer has 15+ years of experience as an architect and developer of enterprise ERP solutions and web applications with a main focus on efficient and performant business processes, usability and application design. He has successfully connected main players in the B2B field by implementing and managing cross-party EDI strategies. In his current role as a Technology Strategist in Compuware's Centre of Excellence team he influences the Compuware APM product strategy by working closely with customers and driving their performance management and improvement at the front line. Follow him @HZeitlhofer

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@BigDataExpo Stories
Samsung VP Jacopo Lenzi, who headed the company's recent SmartThings acquisition under the auspices of Samsung's Open Innovaction Center (OIC), answered a few questions we had about the deal. This interview was in conjunction with our interview with SmartThings CEO Alex Hawkinson. IoT Journal: SmartThings was developed in an open, standards-agnostic platform, and will now be part of Samsung's Open Innovation Center. Can you elaborate on your commitment to keep the platform open? Jacopo Lenzi: S...
Samsung promises to be one of the 800-pound gorillas of the IoT, if its success in recent years with Android devices and other consumer electronics is any guide. Showing its willingness to be a big IoT player, the company recently acquired SmartThings, a recent startup that's developed an open smarthome appliation that currently supports 1,000 devices and 8,000 apps. SmartThings will now work under the auspices of Samsung's Open Innovation Center (OIC). SmartThings Founder and CEO Alex Hawkinson...
The major cloud platforms defy a simple, side-by-side analysis. Each of the major IaaS public-cloud platforms offers their own unique strengths and functionality. Options for on-site private cloud are diverse as well, and must be designed and deployed while taking existing legacy architecture and infrastructure into account. Then the reality is that most enterprises are embarking on a hybrid cloud strategy and programs. In this Power Panel at 15th Cloud Expo, moderated by Ashar Baig, Research ...
In her General Session at 15th Cloud Expo, Anne Plese, Senior Consultant, Cloud Product Marketing, at Verizon Enterprise, will focus on finding the right mix of renting vs. buying Oracle capacity to scale to meet business demands, and offer validated Oracle database TCO models for Oracle development and testing environments. Anne Plese is a marketing and technology enthusiast/realist with over 19+ years in high tech. At Verizon Enterprise, she focuses on driving growth for the Verizon Cloud pla...
As Platform as a Service (PaaS) matures as a category, developers should have the ability to use the programming language of their choice to build applications and have access to a wide array of services. Bluemix is IBM's open cloud development platform that enables users to easily build cloud-based, creative mobile and web applications without having to spend large amounts of time and resources on configuring infrastructure and multiple software licenses. In this track, you will learn about the...
General Electric (GE) has been a household name for more than a century, thanks in large part to its role in making households easier to run. Starting with the light bulb invented by its founder, Thomas Edison, GE has been selling devices (“things”) to consumers throughout its 122-year history. Last week, GE announced that it is officially leaving that job to others. While the lighting division will stay, GE will now turn its attention to selling industrial machinery and analytics as a service t...
The Internet of Things will greatly expand the opportunities for data collection and new business models driven off of that data. In her session at Internet of @ThingsExpo, Esmeralda Swartz, CMO of MetraTech, will discuss how for this to be effective you not only need to have infrastructure and operational models capable of utilizing this new phenomenon, but increasingly service providers will need to convince a skeptical public to participate. Get ready to show them the money! Speaker Bio: ...
How do you know when a technology has become mainstream? A good clue may be when politicians start talking about it on the campaign trail and with mainstream media. David Cameron, the UK prime minister, was the latest, indicating that the world was now on “fast-forward” with the Internet of Things (IoT) ushering in the new industrial revolution. No mention of IoT targeted at the masses would be complete without the clichéd example of the communicating fridge. While it is easy to get caught up in...
Machine-to-machine (M2M) technology and the resulting Internet of Things are leading us inexorably toward everything-as-a-service (XaaS). As more things get connected, the range of service opportunities expands. And as those services are presented online, they become available for use, re-use and re-purposing. At first thought, the idea of more connected devices suggests simply that there will be more devices around, and as such, more products for manufacturers to make and sell. That’s true, bu...
Almost everyone sees the potential of Internet of Things but how can businesses truly unlock that potential. The key will be in the ability to discover business insight in the midst of an ocean of Big Data generated from billions of embedded devices via Systems of Discover. Businesses will also need to ensure that they can sustain that insight by leveraging the cloud for global reach, scale and elasticity.
SAP is delivering break-through innovation combined with fantastic user experience powered by the market-leading in-memory technology, SAP HANA. In his General Session at 15th Cloud Expo, Thorsten Leiduck, VP ISVs & Digital Commerce, SAP, will discuss how SAP and partners provide cloud and hybrid cloud solutions as well as real-time Big Data offerings that help companies of all sizes and industries run better. SAP launched an application challenge to award the most innovative SAP HANA and SAP ...
The Internet of Things (IoT) is going to require a new way of thinking and of developing software for speed, security and innovation. This requires IT leaders to balance business as usual while anticipating for the next market and technology trends. Cloud provides the right IT asset portfolio to help today’s IT leaders manage the old and prepare for the new. Today the cloud conversation is evolving from private and public to hybrid. This session will provide use cases and insights to reinforce t...
SYS-CON Events announced today that Verizon has been named "Gold Sponsor" of SYS-CON's 15th International Cloud Expo®, which will take place on November 4-6, 2014, at the Santa Clara Convention Center in Santa Clara, CA. Verizon Enterprise Solutions creates global connections that generate growth, drive business innovation and move society forward. With industry-specific solutions and a full range of global wholesale offerings provided over the company's secure mobility, cloud, strategic network...
SimpleECM is the only platform to offer a powerful combination of enterprise content management (ECM) services, capture solutions, and third-party business services providing simplified integrations and workflow development for solution providers. SimpleECM is opening the market to businesses of all sizes by reinventing the delivery of ECM services. Our APIs make the development of ECM services simple with the use of familiar technologies for a frictionless integration directly into web applicat...
The only place to be June 9-11 is Cloud Expo & @ThingsExpo 2015 East at the Javits Center in New York City. Join us there as delegates from all over the world come to listen to and engage with speakers & sponsors from the leading Cloud Computing, IoT & Big Data companies. Cloud Expo & @ThingsExpo are the leading events covering the booming market of Cloud Computing, IoT & Big Data for the enterprise. Speakers from all over the world will be hand-picked for their ability to explore the economic...
Cloudwick, the leading big data DevOps service and solution provider to the Fortune 1000, announced Big Loop, its multi-vendor operations platform. Cloudwick Big Loop creates greater collaboration between Fortune 1000 IT staff, developers and their database management systems as well as big data vendors. This allows customers to comprehensively manage and oversee their entire infrastructure, which leads to more successful production cluster operations, and scale-out. Cloudwick Big Loop supports ...
Software AG helps organizations transform into Digital Enterprises, so they can differentiate from competitors and better engage customers, partners and employees. Using the Software AG Suite, companies can close the gap between business and IT to create digital systems of differentiation that drive front-line agility. We offer four on-ramps to the Digital Enterprise: alignment through collaborative process analysis; transformation through portfolio management; agility through process automation...
Headquartered in Santa Monica, California, Bitium was founded by Kriz and Erik Gustavson. The 1,500 cloud-based application using Bitium’s analytics, app management, and single sign-on services include bug trackers, customer service dashboards, Google Apps, and social networks. The firm states website administrators can do multiple tasks online without revealing passwords. Bitium’s advisors include Microsoft’s former CMO and the former senior vice president of strategy, the founder and CEO of Li...
Things are being built upon cloud foundations to transform organizations. This CEO Power Panel at 15th Cloud Expo, moderated by Roger Strukhoff, Cloud Expo and @ThingsExpo conference chair, will address the big issues involving these technologies and, more important, the results they will achieve. How important are public, private, and hybrid cloud to the enterprise? How does one define Big Data? And how is the IoT tying all this together?
The 3rd International Internet of @ThingsExpo, co-located with the 16th International Cloud Expo - to be held June 9-11, 2015, at the Javits Center in New York City, NY - announces that its Call for Papers is now open. The Internet of Things (IoT) is the biggest idea since the creation of the Worldwide Web more than 20 years ago.