Wednesday, August 17, 2011

nginx configuration

To enhance the performance and security of my web server , few days back i decided to use Reverse proxy theory. My idea was to put a a lightweight web server in front of my apache web sever to serve all the static contents by that lightweight web server, and dynamic content by main backend apache web server. In my study, I found that Apache itself can implement reverse-proxy, but i decided to go for lightweight web server. In my learning process i got some good feedback for lighttpd , but nginx is more popular (Based on stuffs i got by googling).


I decided to go with nginx for testing and deployment.

After installing nginx, Initially i done following configuration in default ngnix sitesconfiguration file, in my case it is (/etc/nginx/sites-available/default)

server {

listen 80;

servername test.com;

accesslog /var/log/nginx/access.log;

location / {

proxypass 127.0.0.1:8080;

}

location /images {

root /data/web/images;

autoindex on;

}

}

I my example my apache server is running on port 8080. Here reverse proxy concept is used to to forward all home page accessing(http://mysite.com), to port 8080 on localhost (in our case apache is running on 8080). All access to http://test.com/images will served directly by nginx.