Saturday, October 30, 2010

Nginx installation

Nginx installation and configuration on Centos5

1.Installing Nginx and required modules

first we can install the most important packages for nginx

for my case i have downloaded the pcre,zlib,openssl packages to /opt/nginx-0.7.67 (Where nginx-0.7.67 is from untared nginx)
cd /opt/nginx-0.7.67
#wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.10.tar.gz
(pcre for regular expressions)
#tar -xvf pcre-8.10.tar.gz
#./configure
#make
#make install

#wget http://zlib.net/zlib-1.2.5.tar.gz
#tar -xvf zlib-1.2.5.tar.gz
#./configure
#make
#make install

#wget ftp://ftp.openssl.org/source/openssl-0.9.8o.tar.gz
#tar -xvf openssl-0.9.8o.tar.gz
#./config
#make
#make install

#cd /opt
#wget http://nginx.org/download/nginx-0.7.67.tar.gz
#tar -xvf nginx-0.7.67.tar.gz
#cd nginx-0.7.67

# ./configure --prefix=/etc/nginx --user=nginx --group=nginx --with-http_ssl_module --without-http_rewrite_module --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --with-pcre --with-pcre=/opt/nginx-0.7.67/pcre-8.10/ --with-openssl=/opt/nginx-0.7.67/openssl-0.9.8o/ --with-zlib=/opt/nginx-0.7.67/zlib-1.2.5/
# make
# make install

useradd -M -r --shell /sbin/nologin --home-dir /etc/nginx nginx

# /etc/rc.d/init.d/nginx restart
/etc/rc.d/init.d/nginx: line 67: /opt/nginx/sbin/nginx: No such file or directory

#vi /etc/rc.d/init.d/nginx

nginx="/etc/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/conf/nginx.conf"

Next we have to install spawn-fcgi for loading php pages for your web site.
#cd /opt/nginx-0.7.67
#wget http://www.lighttpd.net/download/lighttpd-1.4.18.tar.bz2
#tar -xvjf lighttpd-1.4.18.tar.bz2
#cd lighttpd-1.4.18/
#./configure
#make
#sudo cp src/spawn-fcgi /usr/bin/spawn-fcgi
#cd ..
#rm -rf lighttpd-1.4.18/
#rm lighttpd-1.4.18.tar.bz2
#/usr/bin/spawn-fcgi -f /usr/bin/php-cgi -a 127.0.0.1 -p 9000 -P /var/run/ajeesh.pid

2. configuring site

mkdir -p /home/ajeesh/public_html/
mkdir /home/ajeesh/public_html/logs
chown -R nginx:nginx /home/ajeesh/public_html

mkdir /etc/nginx/conf/sites-available
mkdir /etc/nginx/conf/sites-enabled

open your nginx conf file and inserver include
include /etc/nginx/conf/sites-enabled/*; --> under your another virtual host using mix of IP-, name-, and port-based configuration on /etc/nginx/conf/nginx.conf

open vi /etc/nginx/conf/sites-available/ajeesh.com

server {
listen 81;
server_name www.ajeesh.com ajeesh.com;
access_log /home/ajeesh/public_html/logs/access.log;
error_log /home/ajeesh/public_html/logs/error.log;

location / {
root /home/ajeesh/public_html;
index index.html index.htm;
}

location ~ \.php$ {
include /etc/nginx/conf/fastcgi_params;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/ajeesh/public_html/www.ajeesh.com/public_html$fastcgi_script_name;
}
}

# cd /etc/nginx/conf/sites-enabled
# ln -s /etc/nginx/conf/sites-available/ajeesh.com
# service nginx start

No comments:

Post a Comment