批量生成nginx配置文件

現有7個目錄下面分別有30個站的數據,總共是210個站的數據,現在要讓他做備份服務器,就要把nginx的環境配置好,顯然手動配置超級慢,這裏寫了一個腳本,可以批量生成nginx的虛擬主機的文件。
不動的可以問,但不可以說髒話。
#/bin/bash

find ./  -maxdepth 3 -type d -name "*.com"  | sed 's#.\/#\/www\/backup\/#' > /root/zhan.txt
find ./  -maxdepth 3 -type d -name "*.net"  | sed 's#.\/#\/www\/backup\/#' >> /root/zhan.txt
find ./  -maxdepth 3 -type d -name "*.org"  | sed 's#.\/#\/www\/backup\/#' >> /root/zhan.txt
find ./  -maxdepth 3 -type d -name "*.cn"  | sed 's#.\/#\/www\/backup\/#' >> /root/zhan.txt


for wwwpath in `cat /root/zhan.txt`
do
domain=`echo $wwwpath | awk -F/ '{print $6}'`
domain=`echo $domain | awk -F. '{ if ( NF == 2 ) {print "www."$0} else {print $0}}'`
echo $domain
echo $wwwpath
cat > /root/vhost/$domain.conf <<EOF
server
    {
        listen       80;
        server_name  $domain ;
        index index.html index.htm index.php;
        root  $wwwpath ;

        limit_rate 30M;
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|html|htm)$
            {
                expires      30d;
            }

        location ~ .*\.(js|css)?$
            {
                expires      12h;
            }

    }
EOF
done
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章