Reducing the load on a small VPS by 80% in 5 minutes.
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files.
cd /root
wget http://nginx.org/download/nginx-0.8.52.tar.gz
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar xvzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
cd /root
tar xvzf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make
make install
cd /root
tar xvzf nginx-0.8.52.tar.gz
cd nginx-0.8.52
./configure --with-http_ssl_module --with-http_realip_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module
make
make install
Login to WHM and look for the following route:
Main >> Service Configuration >> Apache Setup > Include Editor > Pre Main Include
Add the following configuration and save, LIST_OF_YOUR_IPS changing the IP you use in your site:
LoadModule rpaf_module modules/mod_rpaf-2.0.so RPAFenable On
# Enable reverse proxy add forward RPAFproxy_ips 127.0.0.1 LIST_OF_YOUR_IPS
# which ips are forwarding requests to us RPAFsethostname On
# let rpaf update vhost settings
# allows to have the same hostnames as in the "real"
# configuration for the forwarding Apache RPAFheader X-Real-IP
# Allows you to change which header mod_rpaf looks
# for when trying to find the ip the that is forwarding
# our requests
Change the apache port to 81 (tweak settings)
Open whm – tweak settings and find 0.0.0.0:80 and change it to 0.0.0.0.:81
Thank back SSH console and run:
/usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
/scripts/rebuildhttpdconf httpd restart
create automated nginx virtual host creator
touch nginx.sh
chmod 755 nginx.sh
nano nginx.sh
Add this script to nginx.sh
#!/bin/sh
Â
cat > "/usr/local/nginx/conf/nginx.conf" <<EOF
user nobody;
# no need for more workers in the proxy mode
worker_processes 1;
Â
error_log logs/error.log info;
Â
worker_rlimit_nofile 8192;
Â
events {
 worker_connections 512; # you might need to increase this setting for busy servers
 use epoll; # Linux kernels 2.4.x change to rtsig
}
Â
http {
 server_names_hash_max_size 2048;
Â
 include   mime.types;
 default_type application/octet-stream;
Â
 sendfile on;
 tcp_nopush on;
 tcp_nodelay on;
Â
 keepalive_timeout 10;
Â
 gzip on;
 gzip_min_length 1100;
 gzip_buffers 4 32k;
 gzip_types   text/plain application/x-javascript text/xml text/css;
 ignore_invalid_headers on;
Â
 client_header_timeout 3m;
 client_body_timeout 3m;
 send_timeout    3m;
 connection_pool_size 256;
 client_header_buffer_size 4k;
 large_client_header_buffers 4 32k;
 request_pool_size 4k;
 output_buffers  4 32k;
 postpone_output 1460;
Â
 include "/usr/local/nginx/conf/vhost.conf";
}
Â
EOF
Â
/bin/cp /dev/null /usr/local/nginx/conf/vhost.conf
Â
cd /var/cpanel/users
for USER in *; do
 for DOMAIN in `cat $USER | grep ^DNS | cut -d= -f2`; do
 IP=`cat $USER|grep ^IP|cut -d= -f2`;
 ROOT=`grep ^$USER: /etc/passwd|cut -d: -f6`;
 echo "Converting $DOMAIN for $USER";
Â
 cat >> "/usr/local/nginx/conf/vhost.conf" <<EOF
  server {
 access_log off;
Â
 error_log logs/vhost-error_log warn;
 listen   80;
 server_name $DOMAIN www.$DOMAIN;
Â
 # uncomment location below to make nginx serve static files instead of Apache
 # NOTE this will cause issues with bandwidth accounting as files wont be logged
 #location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|js|css)$ {
 # root  $ROOT/public_html;
 #}
Â
 location / {
  proxy_send_timeout  90;
  proxy_read_timeout  90;
Â
  proxy_buffer_size   4k;
  # you can increase proxy_buffers here to suppress "an upstream response
  # is buffered to a temporary file" warning
  proxy_buffers    16 32k;
  proxy_busy_buffers_size 64k;
  proxy_temp_file_write_size 64k;
Â
  proxy_connect_timeout 30s;
Â
  proxy_redirect http://www.$DOMAIN:81  http://www.$DOMAIN;
  proxy_redirect http://$DOMAIN:81  http://$DOMAIN;
Â
  proxy_pass  http://$IP:81/;
Â
  proxy_set_header  Host  \$host;
  proxy_set_header  X-Real-IP \$remote_addr;
  proxy_set_header  X-Forwarded-For \$proxy_add_x_forwarded_for;
 }
 }
EOF
 done
done
then run it:
./nginx.sh
Check the configuration
/usr/local/nginx/sbin/nginx -t
Until now only the managing nginx connections, but is not serving static content. For the latter you must edit the following file:
nano /usr/local/nginx/conf/vhost.conf
Remove the 3 # signs of the following lines:
#location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|js|css)$ {
# root /home/myweb/public_html;
#}
so the final configuration will looks like
location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|js|css)$ {
root /home/myweb/public_html;
}
./nginx.sh#sthash.egNlfKnv.dpuf
Configure nginx startup scripts
touch /etc/init.d/nginx
chmod +x /etc/init.d/nginx
nano /etc/init.d/nginx
Â
Now add inside the following content
Now add inside the following content
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
# Taken from http://www.hikaro.com
# chkconfig:Â Â - 85 15
# description:Â Nginx is an HTTP(S) server, HTTP(S) reverse \
#Â Â Â Â Â Â Â Â Â Â Â Â Â Â proxy and IMAP/POP3 proxy server
# processname: nginx
# config:Â Â Â Â Â /usr/local/nginx/conf/nginx.conf
# pidfile:Â Â Â Â /usr/local/nginx/logs/nginx.pid
Â
# Source function library.
. /etc/rc.d/init.d/functions
Â
# Source networking configuration.
. /etc/sysconfig/network
Â
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
Â
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
Â
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
Â
lockfile=/var/lock/subsys/nginx
Â
start() {
   [ -x $nginx ] || exit 5
   [ -f $NGINX_CONF_FILE ] || exit 6
   echo -n $"Starting $prog: "
   daemon $nginx -c $NGINX_CONF_FILE
   retval=$?
   echo
   [ $retval -eq 0 ] && touch $lockfile
   return $retval
}
Â
stop() {
   echo -n $"Stopping $prog: "
   killproc $prog -QUIT
   retval=$?
   echo
   [ $retval -eq 0 ] && rm -f $lockfile
   return $retval
}
Â
restart() {
   configtest || return $?
   stop
   start
}
Â
reload() {
   configtest || return $?
   echo -n $"Reloading $prog: "
   killproc $nginx -HUP
   RETVAL=$?
   echo
}
Â
force_reload() {
   restart
}
Â
configtest() {
 $nginx -t -c $NGINX_CONF_FILE
}
Â
rh_status() {
   status $prog
}
Â
rh_status_q() {
   rh_status >/dev/null 2>&1
}
Â
case "$1" in
   start)
       rh_status_q && exit 0
       $1
       ;;
   stop)
       rh_status_q || exit 0
       $1
       ;;
   restart|configtest)
       $1
       ;;
   reload)
       rh_status_q || exit 7
       $1
       ;;
   force-reload)
       force_reload
       ;;
   status)
       rh_status
       ;;
   condrestart|try-restart)
       rh_status_q || exit 0
           ;;
   *)
       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
       exit 2
esac
test the scripts:
/etc/init.d/nginx restart
ps aux | grep nginx
add nginx as autostart deamon
/sbin/chkconfig nginx on
/sbin/chkconfig --list | grep nginx
Enjoy speed of nginx
then run it
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files.Â
Run SSH console
cd /root
wget http://nginx.org/download/nginx-0.8.52.tar.gz
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-7.9.tar.gz
tar xvzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
/usr/local/apache/bin/apxs -i -c -n mod_rpaf-2.0.so mod_rpaf-2.0.c
cd /root
tar xvzf pcre-7.9.tar.gz
cd pcre-7.9
./configure
make
make install
cd /root
tar xvzf nginx-0.8.52.tar.gz
cd nginx-0.8.52
./configure --with-http_ssl_module --with-http_realip_module --with-http_dav_module --with-http_flv_module --with-http_gzip_static_module
make
make install
- See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf
In this setup, NGinx will be integrated with Apache (under cPanel) and used to server the static files. - See more at: http://softescu.ro/blog/knowledge-center/nginx-apache-and-cpanel-cpanel#sthash.egNlfKnv.dpuf