nginx + apache and cPanel
How to accelerate cPanel web hosting server with nginx?
You can find a lot of answers through the Internet, like this:
cPanel forums
24x7servermanagement
All methods are good, but there is one big problem with script (postwwwacct) which was suggested by somebody. It is useless if you are using Addon and Sub domains. This script set wrong homedir for sub- and addon- domains in config.
I wouldn’t rewrite all solution, you can find it easily. But I wrote my own script which generate vhosts.cfg
I think it will put on in right place.
You can get it simply:
wget http://lanselot.me/scripts/postwwwacct
In variable VHOSTFILE set destination of your vhost config file.
#!/bin/bash
#Lanselot 2011
VHOSTFILE=”/opt/nginx/conf/vhosts.cfg”
/bin/cp /dev/null $VHOSTFILEfunction writevhosts {
for DOMAIN in $@ ; do
ROOT=`cat /var/cpanel/userdata/$USER/”$DOMAIN” | grep documentroot | awk ‘{print $2}’`
ALIASES=`cat /var/cpanel/userdata/$USER/”$DOMAIN” | grep serveralias | sed “s/serveralias: //g” | sed “s/www\.\*\.$DOMAIN//g”`
cat >> “$VHOSTFILE” <server {
access_log /dev/null;
error_log /dev/null;
listen 80;
server_name $DOMAIN $ALIASES;gzip on;
gzip_min_length 1100;
gzip_buffers 4 16k;
gzip_types text/plain text/css text/javascript application/x-javascript;
location ~* .(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|mp3|wav|zip|tar|gz|rar|7z)$ {
try_files \$uri @proxy_backend;
gzip off;
root $ROOT;
}location ~* .(js|css)$ {
try_files \$uri @proxy_backend;
gzip on;
root $ROOT;
}location @proxy_backend {
client_max_body_size 64m;
client_body_buffer_size 128k;proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
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;
}location / {
client_max_body_size 64m;
client_body_buffer_size 128k;proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
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
}cd /var/cpanel/users
for USER in *; do
TOTALLINES=`cat /var/cpanel/userdata/$USER/main|wc -l`
SUBLINE=`grep -n sub_domains /var/cpanel/userdata/$USER/main | awk -F ":" '{print $1}'`
IP=`cat /var/cpanel/users/$USER|grep ^IP|cut -d= -f2`;
#SUBDOMAIN and ADDONS
TOT1=`echo "$TOTALLINES-$SUBLINE" | bc`
for SUB in `cat /var/cpanel/userdata/$USER/main | tail -n $TOT1 | awk '{print $2}' | xargs -L100` ; do
writevhosts $SUB
done
#MAIN DOMAIN and his aliases
DOMAIN=`grep main_domain /var/cpanel/userdata/$USER/main | awk '{print $2}' `
writevhosts $DOMAIN
done