Nginx – Small, But Very Powerful and Efficient Web Server
Today, I want to describe one of the interesting tools I am using in my job. This tool is nginx – small, but very powerful and efficient web server created by Igor Sysoev for large Russian web company Rambler and kindly provided by open-source community. This server can be used as standalone HTTP-server and as reverse proxy server before some Apache or another “big” server” to reduce load to backend server by many concurrent HTTP-sessions. As standalone web server, nginx can easily handle huge http-load on static files (images, html-pages, etc).
Main features of nginx server:
- Handling requests to static content, automatical handling of index files and building directory listings.
- Accelerated proxying without caching, simple load banancing and fail-over.
- Accelerated support of remote FastCGI servers with simple load banancing and fail-over.
- Modules and filters including compression (gzip), byte-ranges, chunked responses, SSI-filter, concurrently executed FastCGI or proxy subrequests from one SSI-page.
- SSL-support.
Advanced features of nginx server:
- IP-based and name-based virtual servers.
- Support for keep-alive and pipelined connections.
- Flexible configurations like in Apache, tunable timeouts and buffers.
- Config file and even executable file updating without any termination in service.
- Tunable log files with fast rotation.
- Special pages for errors 400-599.
- Very efficient URI rewriting with regular expressions.
- Access rules based on client’s IP address and on pasword (Basic auth).
- Download speed limits.
Main architecture specifics of nginx server:
- One management and many worker processes; workers are running from non-privileged user.
- Support for different techniques for asynchronous sockets handling: kqueue (FreeBSD 4.1+), epoll (Linux 2.6+), rt signals (Linux 2.2.19+), /dev/poll (Solaris 7 11/99+), select and poll.
- sendfile() system call support: sendfile (FreeBSD 3.1+), sendfile (Linux 2.2+), sendfile64 (Linux 2.4.21+) and sendfilev (Solaris 8 7/01+).
- Accept-filters support on FreeBSD 4.1+ and TCP_DEFER_ACCEPT on Linux 2.4+.
- Very efficient memory handling: it needs only 2.5Mbytes of RAM for 10000 inactive keep-alive connections.
- Minimum of memory copying operations
As an experimental feature, perl interpreper integration can be turned on in nginx.
As for my job, we are using nginx as a primary software for free hosting platforms. I have developed specific modules for banner inserting and stats calculation in nginx and now our central server can handle about 150-200Mbit/s of highly fragmented http-traffic (all files are small). I think, this is really good result bacause with any possible tunnings of Apache on the same servers we were not able to handle even 60-80Mbit/s.
IMHO, main problem of this server is lack of English documentation. As far as i know, its author is really busy and have no time to translate documentation to English. I hope, this article gave you main ideas of what nginx is and why I think that it is the best of lightweight http-servers in the world.
Related posts:

18 Responses to this entry
Consider trying lighttpd then. Very similar capabilities – more features – better documentation.
I’ve tried to use it and have compared it with nginx. Its performance is very poor comparing to nginx. Nginx uses very efficient connection handling algorithms and that is why it is more preferable for high loads.
That would be rather weird, since if your web page is correct they use exactly the same system: epoll on Linux 2.6, kqueue on FreeBSD, etc…
Is there some English documentation on how to set up nginx to serve PHP+FastCGI? I’m interested in some benchmarking.
I will post sample configuration for nginx+php+fcgi there tomorrow.
Thanks for the great write up!
I would be really interested to see your configuration. Can it compress dynamic content? Do you use it as a front end to apache or as a standalone web server?
How did it compare to lighttpd number wise?
[...] In one of my previous posts I have described very powerful Unix admin tool – Nginx. As I said, main problem of this server is lack of English documentation. That is why I decided to write this post with list of typical nginx configurations and example configuration snippets for these configurations. [...]
[...] After my first post about nginx web and reverse-proxy server, I have received many e-mail comments and questions. One of the most popular questions was “How to use PHP with nginx?”. This small howto-like article is about how to do it. [...]
Alexey,
As I’m sure you know already, some of us have set up a wiki for Nginx and are working on getting English, and German translations completed and the Russian documention ported:
http://wiki.codemongers.com/Nginx
Hope this helps others give Nginx a try.
[...] Homo-Adminus Blog » Nginx – Small, But Very Powerful and Efficient Web Server [...]
I am trying to install nginx to act as a reverse proxy on a Linksys NSLU2 with Unslung 5.5 Linux operating system.
I have followed the tutorial here:
http://www.nslu2-linux.org/wiki/HowTo/ReverseProxy
and all is well until I get to the part where I modify the nginx.conf file to add the Cherokee server as per the tutorial extract below:
>>
At this point of the proceedings I should be able to see the Cherokee server at
:7007/cherokee/
but no luck.
I am also trying to proxy the web interface of my router at 192.168.1.254
Similarly for the router page at
:7007/router/
My nginx.conf file is as shown below.
Have I added the proxy lines to the config file correctly?
Thanks for your help.
************************
My nginx.conf file.
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include conf/mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#gzip on;
server {
#listen 80;
listen 7007;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#proxy Cherokee
location /cherokee/ {
proxy_pass http://127.0.0.1:8008;
proxy_redirect default;
}
#proxy Router
location /router/ {
proxy_pass http://192.168.1.254:80;
proxy_redirect default;
}
}
}
Hey, I am thinking about using nginx as a reverse proxy in front of Tomcat. Have anyone done it before ?
Алексей, добрый день.
Возникла проблема и решения пока не нашёл.
Загружаю файл *.asf который после аплоада обрабатывается mencoder’ом, но после того как файл закинут на сервер и начата обработка менкодером, сервер выдаёт 504ю ошибку.
как с этим можно бороться?
[...] Nginx – Small, But Very Powerful and Efficient Web Server (tags: nginx web sysadmin ruby rails blog) [...]
Скажите, какой максимальный размер отдаваемого статического файла?
[...] suplimentara la : http://nginx.net/ http://blog.kovyrin.net/2006/04/04/nginx-small-powerful-web-server/ http://blog.kovyrin.net/2006/04/17/typical-nginx-configurations/ [...]
[...] Nginx – Small, But Very Powerful and Efficient Web Server [...]
Так все-таки – как эффективнее использовать Nginx – в связке с апачем как фронтэнд или как замена апача?
Если можно – опишите какую версию nginx Вы используете на том сервере который показал способность держать 150-200Mbit/s и какая у Вас конфигурация nginx, и, если можно, желаза.
С уважением,
Денис
[...] software for free hosting platforms. I have developed specific modules for banner inserting …http://blog.kovyrin.net/2006/04/04/nginx-small-powerful-web-server/www.<b>nginx</b>.eu/download/sources/CHANGES-0.5.txt… only using non-buffered proxy, then [...]