[Beta] Convert to NGINX on a CentOS + cPanel server

Discussion in 'Tutorials' started by Quags, May 21, 2013.

Thread Status:
This thread is more than 60 days old.
  1. Quags

    Quags Administrator Staff Member

    I've been working on a script slowely to convert a cpanel server to nginx for a while. I consider the script now to be good enough to allow others to use it. Some things to consider:

    * tested on centos 5/6
    * only available for cpanel
    * I don't have an easy way to convert back yet (but will add this in and show below how it can be easily removed.
    * You must be able to run commands as root in SSH

    Converting to nginx
    Run the following ssh commands
    Code:
    rsync -a rsync://mirror.trouble-free.net/admin /admin
    /admin/upscripts
    
    1) Install + convert
    Code:
    /admin/convert2nginx yes all
    Nginx will be installed, the apache vhosts converted and started up. But you are not done, you should also

    2) Add to cron
    /etc/cron.d/nginxmonitor.sh is automatically created now, no step needed here anymore.

    3) Remove fileprotect
    Code:
    /scripts/disablefileprotect
    4) Configure mod_rpaf by adding the below to /usr/local/apache/conf/includes/pre_virtualhost_global.conf

    The install process also configured mod_rpaf. Note change RPAFproxy_ips to your server IPs.

    Code:
    LoadModule rpaf_module        modules/mod_rpaf-2.0.so
    <IfModule mod_rpaf-2.0.c>
    RPAFenable On
    # Enable reverse proxy add forward
    RPAFproxy_ips 127.0.0.1 10.0.0.1
    # 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-Forwarded-For
    # Allows you to change which header mod_rpaf looks
    # for when trying to find the ip the that is forwarding
    # our requests
    </IfModule>
    
    Once done restart apache with /scripts/restartsrv_httpd

    So what just happened? /admin/convert2nginx did the following

    * installed nginx
    * installed mod_rpaf
    * converted the vhosts to nginx (/usr/local/nginx/conf/virtual.include)
    * added /admin/nginx_monitor.sh to /etc/rc.d/rc.local
    * created /scripts/legacypostwwwacct and /etc/logrotate.d/nginx
    * change /var/cpanel/cpanel.config to reflect apache_port=0.0.0.0:81
    * added /etc/cron.d/nginxmonitor.sh

    Your steps are to add the cron and configure mod_rpaf, and if needed disable file protect.

    Disabling nginx

    To disable edit /var/cpanel/cpanel.config and change apache_port=0.0.0.0:81 to apache_port=0.0.0.0:80

    Save and run
    killall -9 nginx
    /usr/local/cpanel/whostmgr/bin/whostmgr2 --updatetweaksettings
    /usr/local/cpanel/bin/build_apache_conf
    /scripts/restartsrv_httpd

    nginx_monitor.sh will not run if the apache port is not set to 81

    To remove completely: delete /usr/local/nginx, /etc/logrotate.d/nginx, /scripts/legacypostwwwacct, nginx_monitor from cron and /etc/rc.d/rc.local startup of nginx


    To do

    Add in support for file protect (better to get cloudlinux with cagefs anyway)
    Add in DA support
    Add in removal script
     
    Boris Janevski and Kiran Kumar like this.
  2. Quags

    Quags Administrator Staff Member

    Step 2:
    */2 * * * * /admin/nginx_monitor.sh >/dev/null 2>&1

    Is no longer needed. A cron is created in /etc/cron.d now.
     
  3. Quags

    Quags Administrator Staff Member

    Two new options have been added.
    1)

    touch /admin/.info/cpanelusername_nginximageskip

    To skip nginx from serving images on the username. Why might you want that? If you use mod_rewrite to redirect images to a php script you will need this.

    2)

    touch /admin/.info/cpanelusername_nginxcacheskip

    To skip nginx from using its built in proxy cache. If you frequently update your site and want to see the changes instantly you'll want this.


    To rebuild vhosts run
    /admin/nginxvhostconvert yes hosts
    killall -HUP nginx
     
  4. Boris Janevski

    Boris Janevski New Member

    Please help me understand why I get CGI default page with nginx installed?
    /cgi-sys/defaultwebpage.cgi

    here is screenshot:
    http://s7.postimg.org/btjnccszv/screenshot_849.png

    I followed your procedure, everything looks fine during installation, but I get default page constantly

    What I'm missing here?
     
  5. Boris Janevski

    Boris Janevski New Member

    OK, I've found out why, missing IP under
    RPAFproxy_ips

    Thanks, this script is great!
     
  6. Boris Janevski

    Boris Janevski New Member

    Looks like there is an error after nginx update EasyApache don't work:

    What to do?
     
  7. Quags

    Quags Administrator Staff Member

    Temporarily remove mod_rpaf from any included files,

    rebuild easyapache

    reinstall mod_rpaf


    * There are better ways, for example I know its possible to make custom changes to have mod_rpaf build with easyapache, but I don't have the info right now. I will update it once I do.
     
    Boris Janevski likes this.
  8. Quags

    Quags Administrator Staff Member

  9. Boris Janevski

    Boris Janevski New Member

    I would like to remove mod_rpaf from "any included files" just I'm not sure how to find that files?
    Maybe stupid question, but :D
     
  10. Boris Janevski

    Boris Janevski New Member

    Ok, here is what I did and EasyApache works

    I renamed pre_virtualhost_global.conf from /usr/local/apache/conf/includes to file home2 ( in the same directory, give any name you want ) , rebuild Apache and than renamed home2 back to pre_virtualhost_global.conf
     
  11. blackMORE

    blackMORE New Member

    Did you manage to do a benchmark? i.e. cPanel+Apache vs cPanel+Nginx page speed, CPU and RAM usage/load, Response Time etc..

    It would be most interesting to see from an Admin point of view. Many thanks for your effort.
     
  12. Quags

    Quags Administrator Staff Member

    I have no benchmarks currently on the difference between them.
     
  13. Ahmed Abd El-Ghany

    Ahmed Abd El-Ghany New Member

    Hello
    this script not available now any alternative to convert to Nginx form Apache

    Thank You
     
  14. Quags

    Quags Administrator Staff Member

Thread Status:
This thread is more than 60 days old.

Share This Page