4353 发表于 2014-5-6 12:56:49

手动(批量)添加nginx虚拟主机和rewrite规则

read -p " domain:" domain
       read -p " domain dir:" vhostdir
       read -p "rewrite.conf:" rewrite
       if [ ! -f "/opt/nginx/conf/config/vhost/$domain.conf" ]; then
       echo "==========================="
       echo "domain=$domain"
       echo "==========================="
       else
       echo "==========================="
       echo "$domain is exist!"
       echo "==========================="      
       fi

cat >/opt/nginx/conf/config/vhost/$domain.conf<<eof
server
       {
               listen       80;
               server_name $domain;
               index index.html index.htm index.php default.html default.htm default.php;
               root$vhostdir;

               include $rewrite.conf;
               location ~ .*\.(php|php5)?$
                               fastcgi_passunix:/tmp/php-cgi.sock;
                               fastcgi_index index.php;
                               include fcgi.conf;
                     }

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

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

       }
eof

if [ ! -f /opt/nginx/conf/config/vhost/$rewrite.conf ]; then
echo "Create Virtul Host ReWrite file......"
       touch /opt/nginx/conf/config/vhost/$rewrite.conf
       echo "Create rewirte file successful,now you can add rewrite rule into /opt/nginx/conf/config/vhost/$rewrite.conf."
fi

或者可以用for domain in xxxxx 批量添加虚拟主机

页: [1]
查看完整版本: 手动(批量)添加nginx虚拟主机和rewrite规则