Speed up your website loading time – nginx
1 Comment Published October 2nd, 2009 in performance, plugins, Wordpress.
In my previous article I have wrote on how to store your files on Amazon S3 to distribute the file over different server. In one perspective, its not a really good solutions, as the content serve by my web server and Amazon S3 might have different latency, and will affect my users browsing experience in certain location of the world. There will be a DNS query overhead to make to Amazon S3.
I have found an article on nginx(spelled engine-X), a small web and email proxy server, written by Igor Sysoev for Rambler, a Russian 2nd largest website. Its primary purpose is as a reverse proxy, but it is also can be a web server. A report of a survey conducted by Netcraft shows that nginx hosts 12,676,238 websites, make it the 5th most popular web server now.
The most popular setup is to make nginx as a reverse proxy. It will serve requests to a static content, and it will forward any php request to PHP in cgi mode. nginx was so popular because of its capability to handle alot of request and consume a very small amount of mamory. You can refer to this blog for a benchmark. But
But nginx have some drawbacks, if you are currently running apache. You will loose some of features that apache have. For example, mod_rewrite. nginx have its own rewrite rule. So, you will have to rewrite your rewrite rule. For my situation, I have a shared hosting server. I don’t want to replace apache with nginx, as it will be a lot of trouble to fix all the website. Some of them run wordpress engine, and some CMS that utilizing .htaccess.
As in my previous post, I’ve place some static content on Amazon S3, and I cannot see much improvement. So, I installed nginx on port 81, and configured a virtual host to look for the same content as apache did. It will only serve static content.
This is my nginx.conf configuration file.
user apache apache;
worker_processes 10;
error_log /var/log/nginx/error.log;
pid /var/log/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
error_page 404 /error_pages/404.html;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
keepalive_timeout 3;
tcp_nodelay on;
gzip on;
include /etc/nginx/sites-enabled/* ;
}
and this is one of my virtual host configuration file, in /etc/nginx/sites-enabled/
server {
listen 81;
server_name mydomain.com www.mydomain.com;
error_log /var/log/nginx/domains/mydomain.com.error.log;
access_log /var/log/nginx/domains/mydomain.com.access.log;
location / {
# root /usr/home/user/domains/mydomain.com/public_html ;
set $myroot /var/www/html;
if ($host ~* mydomain\.com$) {
set $myroot /usr/home/user/domains/mydomain.com/public_html;
}
if ($host ~* www\.mydomain\.com$) {
set $myroot /usr/home/user/domains/mydomain.com/public_html;
}
root $myroot;
index index.html index.php;
client_max_body_size 10m;
client_body_buffer_size 128k;
}
Please change mydomain with your own domain name, and the location path accordingly. You can do some benchmarking with free tools from pingdom. It will show you how the files will be loaded individually, the css file, javascripts, and images. In my setup, I change all the location of css files, the background-image attibutes in the css files, and also all the links to any static files in javascript files also.
You should also try wp-cache if you are using wordpress. This is one of the things I’ve done to make the load faster. wp-cache will keep a static html file of your page initially, and will serve the file for the following request. Everytime you update your post, or post a new content, it will serve the static content. You can also set the expiration period, to make sure your visitor will see your latest content on your site.
You should also consider wp-super-cache, php-speedy, parallel-load and built-in wordpress object caching. You should also read this article, telling about wordpress engine problems, and how they encounter it.
If your wordpress site is growing, you should consider all options by now. And maybe a new dedicated server for that site alone
Its up to you now, do a benchmark, on the server side, and also on your client end. To make sure you can serve your visitor well.
No related posts.




1 Response to “Speed up your website loading time – nginx”
Please Wait
Leave a Reply