Nginx is a powerful web server. few large sites start using this web server. This web server is superior in terms of memory usage and requests can be served
Comparison of the number of requests Apache web server, lighttpd and nginx
From the chart above, it appears that Nginx can serve more requests than the other web server.
In terms of memory usage, nginx also not less powerful in this regard.
wow .. amazing ..
To install nginx, it can be done easily. I’m using ubuntu linux maverick 10:10
1. Install nginx, php5-fpm, php5-xcache, php5-mysql
1 |
#apt-get install nginx php5-fpm php5-xcache php5-mysql |
2. Run service php5 fastcgi dan nginx
1 2 |
#service php5-fpm start #service nginx start |
php5-fpm is the service to run php as FastCGI. This service will open port 9000. whereas Nginx is a webserver that uses a standard web server port of 80. check port 80 and 9000 whether or not already listen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#netstat -ntlp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID /Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4751 /nginx tcp 0 0 10.204.7.204:53 0.0.0.0:* LISTEN 1561 /named tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 1561/named tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1160/cupsd tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 1561/named tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4016/php5-fpm tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1341/mysqld tcp6 0 0 :::80 :::* LISTEN 4751/nginx tcp6 0 0 :::53 :::* LISTEN 1561/named tcp6 0 0 ::1:631 :::* LISTEN 1160/cupsd tcp6 0 0 ::1:953 :::* LISTEN 1561/named |
port 80 and port 9000 already listen
3. Change the nginx configuration for processing documents with extensi.php to be processed by php-FastCGI service
1 |
# vi /etc/nginx/sites-available/defa |
Please be as follows, namely by removing the remark and changing some directory locations.
1 2 3 4 5 6 |
location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name; include fastcgi_params; } |
4. Restart nginx #service nginx restart 5. We test. Create the file /var/www/info.php with the following contents:
1 |
Access via browser http://localhost/info.php
TIME benchmarking
Let us compare the performance between the apache with nginx. tool use is apache-bench. This tool is included in the package apache2-utils. how to check:
1 |
# ab -n 100 -c 5 http://localhost/test.php |
Nginx result:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Server Software: nginx/0.7.67 Server Hostname: localhost Server Port: 80 Document Path: /test.php Document Length: 12 bytes Concurrency Level: 5 Time taken for tests: 45.054 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 17000 bytes HTML transferred: 1200 bytes Requests per second: 2.22 [#/sec] (mean) Time per request: 2252.722 [ms] (mean) Time per request: 450.544 [ms] (mean, across all concurrent requests) Transfer rate: 0.37 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.1 0 0 Processing: 1332 2235 239.4 2248 2740 Waiting: 1332 2235 239.4 2248 2740 Total: 1332 2235 239.4 2248 2740 Percentage of the requests served within a certain time (ms) 50% 2248 66% 2330 75% 2432 80% 2469 90% 2540 95% 2622 98% 2688 99% 2740 100% 2740 (longest request) |
Turn off nginx, restart apache and this is the test results.
Apache Results
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Server Software: Apache/2.2.16 Server Hostname: localhost Server Port: 80 Document Path: /test.php Document Length: 12 bytes Concurrency Level: 5 Time taken for tests: 44.936 seconds Complete requests: 100 Failed requests: 0 Write errors: 0 Total transferred: 22300 bytes HTML transferred: 1200 bytes Requests per second: 2.23 [#/sec] (mean) Time per request: 2246.804 [ms] (mean) Time per request: 449.361 [ms] (mean, across all concurrent requests) Transfer rate: 0.48 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 0.3 0 3 Processing: 1304 2229 242.7 2272 2752 Waiting: 1304 2229 242.8 2272 2751 Total: 1304 2229 242.7 2272 2752 Percentage of the requests served within a certain time (ms) 50% 2272 66% 2331 75% 2366 80% 2390 90% 2543 95% 2612 98% 2674 99% 2752 100% 2752 (longest request) |
So little information about how Powerful Web Server Using nginx, php5 FastCGI, xcache on ubuntu 10.10 that when compared to Apache
source: taujago.web.id