I’ve tired from lags on my Centos server with CPanel. Apache was using a lot of RAM and limit visits by maxclients option was not good for my business, so I’ve decided to install Nginx caching server as proxy cacher for Apache server, instruction below:
1.1.1 For apache 2.2 login as root on your server and install mod_rpaf:
cd /root/
mkdir mod_rpaf
cd mod_rpaf/
wget http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
tar xzf 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
If link is not working download mod_rpaf here
This module will allow Apache get the correct IP address of users from Nginx. If this module is not installed, your access_log will be full of 127.0.0.1 visitors, and your statistic software will not recognize them…
1.1.2 Then you need to add this module into Apache config via WHM panel Main > Service Configuration > Apache Setup > Include Editor > Pre Main Include and add the following code:
LoadModule rpaf_module modules/mod_rpaf-2.0.soRPAFenable On
RPAFproxy_ips 127.0.0.1 LIST_OF_YOUR_IPS
RPAFsethostname On
RPAFheader X-Real-IP
DON’T FORGET TO REPLACE “LIST_OF_YOUR_IPS” VALUE, THERE SHOULD BE A LIST OF ALL YOUR IPS ON THE SERVER (space separated)
1.2.1 For apache 2.4 mod_rpaf doesn’t work, in this case need use mod_remoteip
cd /usr/src/
wget https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/metadata/mod_remoteip.c
apxs -cia mod_remoteip.c
in File /usr/local/apache/conf/includes/pre_main_global.conf add following lines:
LoadModule remoteip_module modules/mod_remoteip.so
RemoteIPHeader X-Forwarded-For
RemoteIPTrustedProxy 127.0.0.1 LIST_OF_YOUR_IPS
DON’T FORGET TO REPLACE “LIST_OF_YOUR_IPS” VALUE, THERE SHOULD BE A LIST OF ALL YOUR IPS ON THE SERVER (space separated)
Note! if you still see server IP in logs, open apache config /usr/local/apache/conf/httpd.conf and find line, ensure you have following:
LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
CHECK ALL SYMBOLS CAREFULLY
2. You need to change Apache port from 80 to 81 (or 8081), it can be done via WHM panel Main > Server Configuration >Tweak Settings
find field Apache non-SSL IP/port and change it to 0.0.0.0:81 (or 0.0.0.0:8081) then save.
If you’ll be not able to login into WHM back, try to login via http://whm.yourdomain:81 (or http://whm.yourdomain:8081)
3. Then we need to rebuild Apache config, log in back to console and run:
/scripts/rebuildhttpdconf
4. Change Apache port for checkserverd:
replace "service[httpd]=80" "service[httpd]=81" -- /etc/chkserv.d/httpd
or
replace "service[httpd]=80" "service[httpd]=8081" -- /etc/chkserv.d/httpd
Then you need to restart chkservd via WHM panel Main > Service Configuration > Service manager and simply Save, chkservd will be restarted with new parameters.
5. Install following packages:
yum -y install gcc pcre-devel zlib-devel bc screen
6. Nginx installation from source!
mkdir /usr/local/src/nginx
cd /usr/local/src/nginx
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar xzf nginx-*.tar.gz
cd nginx-*/
./configure
make
make install
ln -s /usr/local/nginx/conf /etc/nginx
If link is not working download Nginx here
Then you need to create following files (code for files inside the link ):
/etc/logrotate.d/nginx
/etc/init.d/nginx
/scripts/nginx
/etc/chkserv.d/nginx
add execution rights:
chmod +x /etc/init.d/nginx /scripts/nginx
add to autostart
ln -s /etc/init.d/nginx /etc/rc3.d/S99nginx
systemctl enable nginx #Centos 7 only
add following line to crond:
echo "*/1 * * * * /scripts/nginx" >> /var/spool/cron/root
restart crond:
/etc/init.d/crond restart
7. Installation is finished, check Nginx config for errors:
/usr/local/nginx/sbin/nginx -t
If everything is OK, reboot Nginx
/etc/init.d/nginx restart