Skip to content

Instantly share code, notes, and snippets.

@Chairo
Created May 3, 2012 13:13
Show Gist options
  • Select an option

  • Save Chairo/2585511 to your computer and use it in GitHub Desktop.

Select an option

Save Chairo/2585511 to your computer and use it in GitHub Desktop.
nginx-proxy.sh
#!/bin/bash
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
echo "Error: You must be root to run this script, please use root to install lnmp"
exit 1
fi
clear
echo "========================================================================="
echo "Nginx proxy only for Debian VPS , Written by Chairo "
echo "========================================================================="
cur_dir=$(pwd)
if [ "$1" != "--help" ]; then
#set main domain name
domain="www.au92.com"
echo "Please input domain:"
read -p "(Default domain: www.au92.com):" domain
if [ "$domain" = "" ]; then
domain="www.au92.com"
fi
echo "==========================="
echo "domain=$domain"
echo "==========================="
#set area
area="america"
echo "Where are your servers located? asia,america,europe,oceania or africa "
read -p "(Default area: america):" area
if [ "$area" = "" ]; then
area="america"
fi
echo "==========================="
echo "area=$area"
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..."
char=`get_char`
dpkg -l |grep mysql
dpkg -P libmysqlclient15off libmysqlclient15-dev mysql-common
dpkg -l |grep apache
dpkg -P apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-common
dpkg -l |grep php
dpkg -P php
#set timezone
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#Disable SeLinux
if [ -s /etc/selinux/config ]; then
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
fi
if [ -s /etc/ld.so.conf.d/libc6-xen.conf ]; then
sed -i 's/hwcap 1 nosegneg/hwcap 0 nosegneg/g' /etc/ld.so.conf.d/libc6-xen.conf
fi
apt-get update
apt-get remove -y apache2 apache2-doc apache2-utils apache2.2-common apache2.2-bin apache2-mpm-prefork apache2-doc apache2-mpm-worker mysql-client mysql-server mysql-common php
killall apache2
apt-get install -y ntpdate
ntpdate -u pool.ntp.org
date
apt-get install -y apt-spy
cp /etc/apt/sources.list /etc/apt/sources.list.bak
apt-spy update
apt-spy -d stable -a $area -t 5
grep null /etc/apt/sources.list.d/apt-spy.list
if [ $? -eq 0 ]; then
cat >/etc/apt/sources.list.d/apt-spy.list<<EOF
deb http://mirror.peer1.net/debian/ stable main #contrib non-free
deb-src http://mirror.peer1.net/debian/ stable main #contrib non-free
deb http://security.debian.org/ stable/updates main
EOF
fi
apt-get update
apt-get autoremove -y
apt-get -fy install
apt-get install -y build-essential gcc g++ make
for packages in build-essential gcc g++ make autoconf automake re2c wget cron bzip2 libzip-dev libc6-dev file rcconf flex vim nano bison m4 gawk less make cpp binutils diffutils unzip tar bzip2 libbz2-dev libncurses5 libncurses5-dev libtool libevent-dev libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlibc openssl libsasl2-dev libxml2 libxml2-dev libltdl3-dev libltdl-dev libmcrypt-dev zlib1g zlib1g-dev libbz2-1.0 libbz2-dev libglib2.0-0 libglib2.0-dev libpng3 libfreetype6 libfreetype6-dev libjpeg62 libjpeg62-dev libjpeg-dev libpng-dev libpng12-0 libpng12-dev curl libcurl3 libmhash2 libmhash-dev libpq-dev libpq5 gettext libncurses5-dev libcurl4-gnutls-dev libjpeg-dev libpng12-dev libxml2-dev zlib1g-dev libfreetype6 libfreetype6-dev libssl-dev libcurl3 libcurl4-openssl-dev libcurl4-gnutls-dev mcrypt;
do apt-get install -y $packages --force-yes;apt-get -fy install;apt-get -y autoremove; done
echo "============================check files=================================="
if [ -s pcre-8.12.tar.gz ]; then
echo "pcre-8.12.tar.gz [found]"
else
echo "Error: pcre-8.12.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/web/pcre/pcre-8.12.tar.gz
fi
if [ -s nginx-1.0.10.tar.gz ]; then
echo "nginx-1.0.10.tar.gz [found]"
else
echo "Error: nginx-1.0.10.tar.gz not found!!!download now......"
wget -c http://soft.vpser.net/web/nginx/nginx-1.0.10.tar.gz
fi
ulimit -v unlimited
if [ ! `grep -l "/lib" '/etc/ld.so.conf'` ]; then
echo "/lib" >> /etc/ld.so.conf
fi
if [ ! `grep -l '/usr/lib' '/etc/ld.so.conf'` ]; then
echo "/usr/lib" >> /etc/ld.so.conf
fi
if [ -d "/usr/lib64" ] && [ ! `grep -l '/usr/lib64' '/etc/ld.so.conf'` ]; then
echo "/usr/lib64" >> /etc/ld.so.conf
fi
if [ ! `grep -l '/usr/local/lib' '/etc/ld.so.conf'` ]; then
echo "/usr/local/lib" >> /etc/ld.so.conf
fi
ldconfig
cat >>/etc/security/limits.conf<<eof
* soft noproc 65535
* hard noproc 65535
* soft nofile 65535
* hard nofile 65535
eof
cat >>/etc/sysctl.conf<<eof
fs.file-max=65535
eof
echo "========================== nginx install ==============================="
groupadd www
useradd -s /sbin/nologin -g www www
mkdir -p /home/wwwroot
chmod +w /home/wwwroot
mkdir -p /home/wwwlogs
chmod 777 /home/wwwlogs
touch /home/wwwlogs/nginx_error.log
mkdir -p /home/cache
chmod +w /home/cache
mkdir -p /home/cachetmp
chmod +w /home/cachetmp
chown -R www:www /home/wwwroot
chown -R www:www /home/cache
chown -R www:www /home/cachetmp
# nginx
cd $cur_dir
tar zxvf pcre-8.12.tar.gz
cd pcre-8.12/
./configure
make && make install
cd $cur_dir
wget http://labs.frickle.com/files/ngx_cache_purge-1.5.tar.gz
tar zxvf ngx_cache_purge-1.5.tar.gz
cd $cur_dir
tar zxvf nginx-1.0.10.tar.gz
cd nginx-1.0.10/
./configure --user=www --group=www --add-module=../ngx_cache_purge-1.5 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module
make && make install
cd $cur_dir
cp conf/proxy.conf /usr/local/nginx/conf/proxy.conf
rm -f /usr/local/nginx/conf/nginx.conf
cp conf/nginx_proxy.conf /usr/local/nginx/conf/nginx.conf
sed -i 's/www.lnmp.org/'$domain'/g' /usr/local/nginx/conf/nginx.conf
cp conf/none.conf /usr/local/nginx/conf/none.conf
#start up
echo "Download new nginx init.d file......"
wget -c http://soft.vpser.net/lnmp/ext/init.d.nginx
cp init.d.nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
echo "Test Nginx Confgure....."
/usr/local/nginx/sbin/nginx -t
echo "Starting Nginx......"
if [ -s /usr/local/nginx/logs/nginx.pid ]; then
kill `cat /usr/local/nginx/logs/nginx.pid`
fi
/usr/local/nginx/sbin/nginx
echo "==================== nginx install completed ==========================="
update-rc.d -f nginx defaults
/etc/init.d/nginx start
cp vhost_proxy-site.sh /root/vhost_proxy-site.sh
chmod +x /root/vhost_proxy-site.sh
cp nginxproxy /root/
chmod +x /root/nginxproxy
echo "===================================== Check install ==================================="
clear
if [ -s /usr/local/nginx ]; then
echo "/usr/local/nginx [found]"
else
echo "Error: /usr/local/nginx not found!!!"
fi
echo "========================== Check install ================================"
echo "Install Nginx proxy only completed! enjoy it."
echo "========================================================================="
echo "Nginx proxy only for Debian VPS , Written by Chairo "
echo "========================================================================="
echo ""
echo "For more information please visit http://www.au92.com/"
echo ""
echo "Nginx proxy only status manage: /root/nginxproxy {start|stop|reload|restart|kill|status}"
echo ""
echo "The path of some dirs:"
echo "nginx dir: /usr/local/nginx"
echo "web dir : /home/wwwroot"
echo ""
echo "========================================================================="
/root/nginxproxy status
netstat -ntl
else
echo "Sorry,Failed to install Nginx proxy only!"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment