下面是我在工作中经常建站所用到的脚本,首先把需要建的虚拟主机域名写到test.txt中然后在开始写下面的脚本,此脚本是在nginx环境下用的
#!/bin/bash
for domain in `cat test.txt`
do
cat >> /usr/local/nginx/conf/vhost/host.conf << EOF或者用下句二者择其一
cat > /usr/local/nginx/conf/vhost/$domain.conf << EOF
server
{
listen 80;
server_name www.$domain $domain;
index index.php index.html index.htm;
root /data0/web/$domain;
error_page 404 = http://www.$domain;
if (!-f \$request_filename){
set \$rule_0 1\$rule_0;
}
if (!-d \$request_filename){
set \$rule_0 2\$rule_0;
}
if (\$rule_0 = "21"){
rewrite ^/(.*)\?*$ /index.php?_route_=\$1 last;
}
if (\$host != 'www.$domain' ) {
rewrite ^/(.*)$ http://www.$domain/\$1 permanent;
}
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
}
EOF
done