dcsimg

Take Off With Nginx

In the market for a high performance HTTP server and reverse proxy server? Take a look at "Engine X."

Nginx, pronounced “Engine X,” is a high performance HTTP server and reverse proxy that is also able to proxy IMAP and POP3. Written by Igor Sysoev and licensed under a BSD variant, the official site is here.

While most of the official site and documentation is in Russian, an English language wiki is available. Nginx has a modular architecture and can serve static content extremely quickly using a high number of concurrent connections. It does accelerated reverse proxying without caching.

If a caching web accelerator is more what you’re looking for, you might look into Varnish, which we covered recently. (See Getting Glossy with Varnish.) Additional HTTP features include simple load balancing, fault tolerance, ACLs, flexible rewriting, FastCGI, and SSL.

Nginx also supports a variety of mail proxy features such as user redirection to IMAP/POP3 backends using an external HTTP authentication server, user authentication using an external HTTP authentication server, SSL, STARTTLS, and STLS. The mail proxy functionality is used in some very high volume implementations, including FastMail.FM and Zimbra.

Setting Up Nginx

Let’s get started with Nginx. After you download the latest tarball from the Nginx site, you can install nginx as follows:


$ ./configure --user=daemon --group=daemon && make

# make install

You’ll need to adjust the configuration flags depending on the functionality you plan on utilizing. For instance, if you’d like to use regular expressions in your configuration file, you’ll need to point configure to the PCRE library.

The default installation path for nginx is /usr/local/nginx. With nginx installed, it’s time to create a configuration file (default: /usr/local/nginx/conf/nginx.conf). This configuration file will serve static content for a single virtual host:


worker_processes  2;

pid/var/run/nginx.pid;

error_loglogs/error.log  info;

events {

    worker_connections  1024;

    use epoll;

}

http {

    includeconf/mime.types;

    default_typeapplication/octet-stream;

    sendfileon;

    gzipon;

    gzip_comp_level5;

    gzip_typestext/html text/plain txt/xml text/css application/x-javascript;

    server {

	listen80;

	server_namewww.domain1.com;

	access_loglogs/domain1.access.log main;

	location / {

	    indexindex.html;

	    root/var/www/domain1.com/htdocs;

	}

    }

}

You can use a regular expression along with the deny directive to block access to all subversion directories.


location ~ /\.svn {

    deny  all;

}

You may want to serve all images with Expires and Cache-Control headers that will allow caching at the browser level, while not clogging the access log.


location ~* ^.+.(jpg|jpeg|gif|png|)$ {

    access_log        off;

    expires           30d;

}

To perform simple load balancing between three servers, one of which is more powerful. This will allow you to do that:


upstream my_cluster {

    server 192.168.1.1 weight=3

	server 192.168.1.2

	server 192.168.1.3

}

server {

    listen    80;

    server_namewww.domain.com;

    access_log	logs/www.domain.access.log main;

    location / {

proxy_passhttp://my_cluster;

	proxy_set_headerHost $host;

	proxy_set_headerX-Real-IP $remote_addr;

	proxy_set_headerHostX-Forwarded-For $proxy_add_x_forwarded_for;

    }

}

Once you’ve finalized your configuration, you should test the syntax with nginx -t. You’re now ready to start serving content. Don’t forget to add nginx to your startup scripts. One nice feature of nginx is that you can upgrade to a new binary without losing a single incoming request.

To accomplish this, replace the old nginx binary with a new one. Then send a USR2 signal to the nginx master process, which will rename its C<.pid> file to .oldbin and then execute the new binary. You can now phase out the old binary by sending its master process a WINCH signal. Once all old worker process are done you can send the old master process a QUIT.

Nginx allows you to quickly and easily serve static content, while giving you the flexibility to proxy dynamic content and other requests to any number of backends. If you have a rapidly growing site, its small memory footprint, secure code and high concurrency could be a welcome addition to your infrastructure.

Comments on "Take Off With Nginx"

bugmenot

Amazing. Thanks Jeremy!
Just one question: How does this compare to lighttpd?

qrkyboy

I don’t know about recently, but lighttpd suffered some leakiness a while back (which is in part why nginx became so popular). I’ve tested nginx for static content and even on smaller servers concurrency+requests I can max out the ethernet without the server hiccuping (this is a dual quad-core Xeon X5355). It simply doesn’t run out of power and easily overpowers Apache for anything static. It’s clumsy on PHP, but Apache is awful on Rails, so it’s a choice of poison. One factor not mentioned here is nginx has Flash streaming available in the binary and some pretty slick stats are possible using rrdtool, and of course gzip compression is available. It’s extremely small, extremely simple to configure, and I’ve never been able to crash it in comparable tests against Apache where Apache ran through all memory and then began to fail. If you’re running Rails, you’ll probably want to run nginx (the dev version 0.6.30 is just as stable in my tests as the “stable” version FYI). I noticed even CNN is using it for their politics blog. I can’t recommend it highly enough, and I’ve been configuring webservers from scratch for almost 15yrs.

gaveen

I’m not sure about generic performance ratings, but I know for a fact that Nginx is very popular in the Ruby on Rails world (used as a HTTP server/proxy/load balancer) and also serves several high traffic sites. Ezra of EngineYard has written several blog posts related to Nginx.

Sorry I couldn’t find the actual benchmarks, but as far as I remember Nginx outperformed everything in Rails cases. Nginxs’ ability to use Unix domain sockets also has been out to use.

Nginx allows you to quickly and easily serve static content, while giving you the flexibility to proxy dynamic content and other requests to any number of Cueb Answers backends. If you have a rapidly growing site, its small memory footprint, secure code and high concurrency could be a welcome addition to your infrastructure.

Whenever you post your personal information online, there is a
potential threat for fraud. In this, the final image is
produced by making use of ultrasound waves which are
enhanced by the Doppler Effect. If there is something unusual or
abnormal, they might decide to investigate further.

Pretty nice post. I just stumbled upon your weblog and wanted to
say that I’ve truly loved browsing your blog posts.
In any case I’ll be subscribing on your feed and I am
hoping you write again very soon!

Also visit my page college undergraduate stress scale

Heya! I knnow this is somewhat off-topic however I had to ask.

Does operating a well-established blog like yours take a lot of work?
I’m brand new to running a blog however I do write in
my diary daily. I’d like to start a blog so I can easily share my experience and
thoughts online. Please let me know if you have any kind of recommendations or tips for brand new
aspiring bloggers. Apprecfiate it!

Do you mind if I quote a few of your articles as long as I provide credit and sources back to your site?

My website is in the exact same area of interest as yours and
my visitors would genuinely benefit from some of the information you present here.
Please let me know if this okay with you. Many thanks!

my weblog … belysning

Hello would you mind stating which blog platform you’re working with?
I’m going to start my own blog in the near future but I’m
having a tough time deciding between BlogEngine/Wordpress/B2evolution and Drupal.
The reason I ask is because your design and style seems different then most blogs and I’m looking for something completely unique.
P.S My apologies for getting off-topic but I had to ask!

Great goods from you, man. I’ve understand your stuff previous to and you are just extremely excellent.
I really like what you have acquired here, certainly
like what you are stating and the way in which you
say it. You make it enjoyable and you still care for to keep
it sensible. I can’t wait to read far more from you. This is really a great site.

I’m gone to tell my little brother, that he should also visit
this webpage on regular basis to get updated from hottest
news update.

Feel free to surf to my page; madden nfl 25
hack (Justina)

Super blog post. Do you post more articles regularly?
My spouse and I honestly loved your post.

Hello my friend! I want to say that this article is amazing,
great written and include approximately all important infos.
I’d like to look more posts like this .

Feel free to surf to my blog post :: ludokado Triche

I absolutely love your blog.. Very nice colors
& theme. Did you create this web site yourself? Please reply back as
I’m attempting to create my own personal site and want to find out where you got this from or
exactly what the theme is called. Thank you!

Its such as you read my mind! You appear to grasp so much about this, like you wrote the ebook in it or something.
I believe that you simply could do with some percent
to power the message house a bit, however instead of
that, that is wonderful blog. A fantastic read. I will certainly be back.

my homepage ????? ???? ??

Hey there just wanted to give you a quck heads up.
The words in your content seem to be running off the screen
in Intenet explorer. I’m not sure if this is a formatting
issue or something to do with browser compatibility but I
figured I’d post to lett you know. The layout look great though!
Hope you get tthe issue fixed soon. Cheers

Hi! I could have sworn I’ve been to this web site before but
after browsing through many of the articles I realized it’s new to me.
Anyhow, I’m certainly happy I found it and I’ll be bookmarking it and checking back regularly!

Here is my web blog: ?? ??

This post will help the internet viewers for creating new
webpage or even a blog from start to end.

my web page … buy mira hair oil

Hi there! This blog post couldn’t be written any better!
Going through this post reminds me of my previous roommate!

He always kept talking about this. I’ll send this informaton to him.

Fairly certaiin he will have a good read. Thanks for sharing!

Feel ffree to surf to myy weblog :: best e cigarette

I read this article fully concerning the resemblance
of latest and previous technologies, it’s remarkable article.

My website: seo Google (Linette)

This site was… how do I say it? Relevant!!
Finally I’ve found something that helped me. Cheers!

It’s a pity you don’t have a donate button! I’d most certainly donate to this outstanding blog! I suppose for now i’ll settle for bookmarking and adding your RSS feed to my Google account. I look forward to brand new updates and will talk about this site with my Facebook group. Talk soon!

Unquestionably believe that which you said. Your favorite reason seemed to be on the net the simplest thing to be aware of. I say to you, I certainly get annoyed while people think about worries that they plainly do not know about. You managed to hit the nail upon the top and defined out the whole thing without having side effect , people could take a signal. Will probably be back to get more. Thanks

Hi there, just became alert to your blog via Google, and located that it is really informative. I’m gonna watch out for brussels. I will be grateful if you happen to proceed this in future. A lot of other people will likely be benefited out of your writing. Cheers!

Woh I enjoy your articles, saved to bookmarks! .

Good day! Do you use Twitter? I’d like to follow you if that would be okay. I’m definitely enjoying your blog and look forward to new posts.

Rattling wonderful info can be found on weblog. “I believe in nothing, everything is sacred. I believe in everything, nothing is sacred.” by Tom Robbins.

Appreciate it for helping out, superb information.

Very well written post. It will be helpful to anybody who employess it, as well as yours truly :). Keep doing what you are doing – looking forward to more posts.

The information and facts mentioned inside the post are several of the top obtainable.

Usually posts some pretty exciting stuff like this. If you?re new to this site.

The data mentioned inside the post are some of the top out there.

Can I just say what a aid to seek out someone who truly knows what theyre speaking about on the internet. You undoubtedly know how one can deliver a difficulty to mild and make it important. More folks have to learn this and perceive this aspect of the story. I cant consider youre no more popular since you definitely have the gift.

The information mentioned within the article are a few of the top out there.

Wonderful story, reckoned we could combine several unrelated data, nevertheless seriously really worth taking a appear, whoa did a single discover about Mid East has got additional problerms too.

Leave a Reply