Created
August 8, 2012 15:29
-
-
Save wdfsinap/3295949 to your computer and use it in GitHub Desktop.
add host for LLNMP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Add virtual host | |
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin | |
export PATH | |
# Check if user is root | |
if [ $(id -u) != "0" ]; then | |
printf "Error: You must be root to run this script!\n" | |
exit 1 | |
fi | |
clear | |
if [ "$1" != "--help" ]; then | |
domain="www.vpssh.org" | |
echo "Please input domain:" | |
read -p "(Default domain: www.vpssh.org):" domain | |
if [ "$domain" = "" ]; then | |
domain="www.vpssh.org" | |
fi | |
if [ ! -f "/usr/local/nginx/conf/servers/$domain.conf" ]; then | |
echo "===========================" | |
echo "domain=$domain" | |
echo "===========================" | |
else | |
echo "===========================" | |
echo "$domain is exist!" | |
echo "===========================" | |
fi | |
hostdir="/home/wwwroot/$domain" | |
echo "Please input the directory for the domain:$domain :" | |
read -p "(Default directory: /home/wwwroot/$domain):" hostdir | |
if [ "$hostdir" = "" ]; then | |
hostdir="/home/wwwroot/$domain" | |
fi | |
echo "===========================" | |
echo Virtual Host Directory="$hostdir" | |
echo "===========================" | |
get_char() | |
{ | |
SAVEDSTTY=`stty -g` | |
stty -echo | |
stty cbreak | |
dd if=/dev/tty bs=1 count=1 2> /dev/null | |
stty -raw | |
stty echo | |
stty $SAVEDSTTY | |
} | |
echo "" | |
echo "Press any key to start create virtul host..." | |
char=`get_char` | |
echo "Create Virtul Host directory......" | |
mkdir -p $hostdir | |
echo "set permissions of Virtual Host directory......" | |
chmod -R 755 $hostdir | |
chown -R www:www $hostdir | |
cat >/usr/local/nginx/conf/servers/$domain.conf<<eof | |
server | |
{ | |
listen 80; | |
server_name $domain; | |
index index.html index.htm index.php; | |
root $hostdir; | |
include /usr/local/nginx/conf/proxy.conf; | |
location / { | |
location ~ .*\.(php|php5)?$ { | |
index index.php; | |
root $hostdir; | |
proxy_pass http://$domain:8088; | |
} | |
if ( !-e \$request_filename) { | |
proxy_pass http://$domain:8088; | |
} | |
location ~* \.(jpg|jpeg|gif|png|swf|htm|html)$ { | |
if (-f \$request_filename) { | |
root $hostdir; | |
expires 30d; | |
break; | |
} | |
} | |
location ~* \.(js|css)$ { | |
if (-f \$request_filename) { | |
root $hostdir; | |
expires 1d; | |
break; | |
} | |
} | |
} | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} | |
eof | |
echo "Test Nginx configure file......" | |
/usr/local/nginx/sbin/nginx -t | |
echo "" | |
echo "Restart Nginx......" | |
/usr/local/nginx/sbin/nginx -s reload | |
mkdir -p $hostdir/conf | |
chmod 777 $hostdir | |
cat >>$hostdir/conf/vhost.xml <<EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<virtualHostConfig> | |
<docRoot>$hostdir</docRoot> | |
<adminEmails></adminEmails> | |
<enableGzip></enableGzip> | |
</virtualHostConfig> | |
EOF | |
sed -e "/\/vhostMapList/i\\<vhostMap\>\n\<vhost\>$domain\<\/vhost\>\n\<domain\>${YOURIP}\<\/domain\>\n\<\/vhostMap\>" -i /usr/local/lsws/conf/httpd_config.xml | |
sed -e "/\/virtualHostList/i\\<virtualHost\>\n\<name\>$domain\<\/name\>\n\<vhRoot\>$hostdir\<\/vhRoot\>\n\<configFile\>$hostdir\/conf\/vhost.xml\<\/configFile\>\n\<note\>\<\/note\>\n\<allowSymbolLink\>0\<\/allowSymbolLink\>\n\<enableScript\>1\<\/enableScript\>\n\<restrained\>1\<\/restrained\>\n\<maxKeepAliveReq\>50\<\/maxKeepAliveReq\>\n\<smartKeepAlive\>\<\/smartKeepAlive\>\n\<setUIDMode\>0\<\/setUIDMode\>\n\<staticReqPerSec\>10\<\/staticReqPerSec\>\n\<dynReqPerSec\>10\<\/dynReqPerSec\>\n\<outBandwidth\>10\<\/outBandwidth\>\n\<inBandwidth\>10\<\/inBandwidth\>\n\<\/virtualHost\>" -i /usr/local/lsws/conf/httpd_config.xml | |
/etc/init.d/lsws restart | |
echo "=========================================================================" | |
echo "Add Virtual Host by LLNMP V0.1 " | |
echo "=========================================================================" | |
echo "Your domain:$domain" | |
echo "Directory of $domain:$hostdir" | |
echo "For more information please visit http://vpssh.org" | |
echo "=========================================================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment