Nginx (pronounced Engine-X) is a russian open source httpd server originally written by Igor Sysoev back in 2005. Nginx is a very light weight httpd server and reverse proxy. It is estimated that approx. 3 per cent of all web servers run nginx. In Russia the number is as high as 20 percent, including some of their biggest web sites. Nginx is also used by Wordpress.com and 4chan.
Why use Nginx instead of Apache or Lighty? Nginx should be fast. I mean FAST. Fast in a way of over 10000 concurrent requests / sec per server. Now that's fast!
I have wanted to screw 'round with Nginx for a while, so here goes nothing!
How to install Nginx on your Linux box
Nginx can be downloaded from www.nginx.net. Simple web page displays the latest distribution packages and small introduction. Further instructions can be found from Nginx Wiki.
I installed Nginx on my CentOs 5.1 running on VMWare & Macbook. Nginx's version was 0.6.32. The default installation is very straightforward - configure, make & make install. I had to install pcre packages to my box before installing httpd server in order to enable rewrite module. I also used --prefix module to install application where i wanted:
[root@cluster1 nginx-0.6.32]# ./configure --prefix=/opt/nginx-0.6.32
[root@cluster1 nginx-0.6.32]# make
[root@cluster1 nginx-0.6.32]# make install
After this Nginx is ready to serve static files!
How to configure Nginx
When you move to your Nginx installation directory, here's what you see:
drwxr-xr-x 2 root root 4096 Oct 5 23:52 sbin
drwxr-xr-x 2 root root 4096 Oct 5 23:52 html
drwxr-xr-x 2 root root 4096 Oct 5 23:52 conf
Sbin directory has only nginx executable file which starts up httpd. Html directory is same as htdocs directory in Apache - copy your files here in order to serve 'em to the world! Conf-file has all configuration files.
When you start up your nginx (just go to sbin and type ./nginx in order to start your web server!) you get few more directories:
drwx------ 2 nobody root 4096 Oct 5 23:52 proxy_temp
drwxr-xr-x 2 root root 4096 Oct 5 23:52 logs
drwx------ 2 nobody root 4096 Oct 5 23:52 fastcgi_temp
drwx------ 2 nobody root 4096 Oct 5 23:52 client_body_temp
In the conf-directory you can see the following files:
-rw-r--r-- 1 root root 3610 Oct 5 23:52 win-utf
-rw-r--r-- 1 root root 2726 Oct 5 23:52 nginx.conf.default
-rw-r--r-- 1 root root 2726 Oct 5 23:52 nginx.conf
-rw-r--r-- 1 root root 2991 Oct 5 23:52 mime.types.default
-rw-r--r-- 1 root root 2991 Oct 5 23:52 mime.types
-rw-r--r-- 1 root root 2223 Oct 5 23:52 koi-win
-rw-r--r-- 1 root root 2837 Oct 5 23:52 koi-utf
-rw-r--r-- 1 root root 909 Oct 5 23:52 fastcgi_params.default
-rw-r--r-- 1 root root 909 Oct 5 23:52 fastcgi_params
The most important file of them all is of course nginx.conf. The default configuration looks like this after installation:
#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;
}
These are default configuration parameters to set user and logging preferences. If you are your box to run many different applications it is a good idea to change default user to something else, like "nginx" or "www_user".
Worker_connections parameter sets the maximum number of connections each worker can handle. This is quite good default value.
The following part defines base settings for the http access:
http {
include mime.types;
default_type application/octet-stream;
You should not tamper round with mime types because you will likely end up with screwed up web server!
If you want to, you can also change default log format in the following part.
#log_format main '$remote_addr - $remote_user [$time_local] $request '
# '"$status" $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
TCP nopush setting means that HTTP response hearders are all sent in one packet. Sendfile setting means that Nginx ignores the details of the file it is sending and uses kernel sendfile support instead. Keepalive setting defines how long server waits for users packets. This should be changed only to few seconds on busy sites. Gzip compression saves bandwith on site, depending what kind of packets server is sending.
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
The following server part is just like server settings on Apache HTTPD and if you have tampered 'round with Apache before this is quite straightforward to you.
server {
listen 80;
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;
}
Example how to configure virtual host on Nginx:
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
These were basic examples of Nginx and what one can do with it. I stripped some configuration examples but here you can see the basics. Later we're going to configure Nginx to use PHP and we're going thru how to use mod_rewrite with Nginx.
Showing posts with label nginx. Show all posts
Showing posts with label nginx. Show all posts
Sunday, October 5, 2008
Sunday, September 14, 2008
How to install Lighttpd with PHP and MySQL to Fedora Core
Lighttpd, or light, is a fast, light and secure webserver which is designed and optimized for speed-critical environments. Many huge websites (Youtube, Wikipedia for example) use lighttpd to serve static content. Also many sites that get more than thousand hits / second use lighty.
Compared to Apache HTTPD or nginx, Lighttpd is not as fust as nginx but it is easier to configure and implement. Compared to Apache, it is faster but has less options. You have to consider which httpd server to use. I personally love to use Apache because of its modules, but I wouldn't hesitate to change to lighty!
1) Install MySQL
First thing you need to do - if you don't allready have MySQL installed - is to install MySQL.
You can do this any way you want, but the easiest way is to use YUM:
yum install mysql mysql-server
Make sure you start mysqld. You should also make sure your mysqld starts when your linux starts up:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
I personally install mysql server from binaries but this is the easiest and fastest way to get your mysql server up and running.
When you install your mysql server, there is no password set for mysql root user. Unless you're using some virtual linux running on your personal laptop used only for developing things, change this immediatelly!
mysqladmin -u root password newpassword
Installing Lighttpd
Since we're using Fedora and we're able to use Yum to install applications, we install lighty this way:
yum install lighttpd
Next, start up your lighty and make sure it starts up when restarting your linux server:
chkconfig --levels 235 lighttpd on
/etc/init.d/lighttpd start
You can now test your ligty. Go to http://127.0.0.1 and you should get a page like this:

3) Install PHP
Lighttpd can use FastCGI to render PHP pages. This can be also installed with YUM:
yum install lighttpd-fastcgi php-cli
That's it! Restart your lighty and you're all good to go!
Compared to Apache HTTPD or nginx, Lighttpd is not as fust as nginx but it is easier to configure and implement. Compared to Apache, it is faster but has less options. You have to consider which httpd server to use. I personally love to use Apache because of its modules, but I wouldn't hesitate to change to lighty!
1) Install MySQL
First thing you need to do - if you don't allready have MySQL installed - is to install MySQL.
You can do this any way you want, but the easiest way is to use YUM:
yum install mysql mysql-server
Make sure you start mysqld. You should also make sure your mysqld starts when your linux starts up:
chkconfig --levels 235 mysqld on
/etc/init.d/mysqld start
I personally install mysql server from binaries but this is the easiest and fastest way to get your mysql server up and running.
When you install your mysql server, there is no password set for mysql root user. Unless you're using some virtual linux running on your personal laptop used only for developing things, change this immediatelly!
mysqladmin -u root password newpassword
Installing Lighttpd
Since we're using Fedora and we're able to use Yum to install applications, we install lighty this way:
yum install lighttpd
Next, start up your lighty and make sure it starts up when restarting your linux server:
chkconfig --levels 235 lighttpd on
/etc/init.d/lighttpd start
You can now test your ligty. Go to http://127.0.0.1 and you should get a page like this:

3) Install PHP
Lighttpd can use FastCGI to render PHP pages. This can be also installed with YUM:
yum install lighttpd-fastcgi php-cli
That's it! Restart your lighty and you're all good to go!
Monday, May 5, 2008
Nginx
Today I ran up to quite intresting product from Russia - Nginx.
Nginx is high performance web and proxy server and, what I have heard, it's capable to run quite high load on very low requirements. Regarding to this article, Wordpress.com is using Nginx as load balancer, handling over 8000 requests / sec. That's quite impressive!
What's best, Nginx is really lightweight. According to testimonials in Nginx wiki, this web server can be run with really low RAM. Excellent.
I'm going to screw 'round with this piece of software now. Going to report you back later!
Nginx is high performance web and proxy server and, what I have heard, it's capable to run quite high load on very low requirements. Regarding to this article, Wordpress.com is using Nginx as load balancer, handling over 8000 requests / sec. That's quite impressive!
What's best, Nginx is really lightweight. According to testimonials in Nginx wiki, this web server can be run with really low RAM. Excellent.
I'm going to screw 'round with this piece of software now. Going to report you back later!
Subscribe to:
Posts (Atom)