Site icon moneyslow.com

批量修改nginx配置文件

nginx安全配置文件最佳实践

nginx安全配置文件最佳实践

nginx配置文件是有好工具的:https://www.digitalocean.com/community/tools/nginx

下面是个例:
数百个千个二级域名,如何批量修改配置文件?
假如域名有很多,有大量nginx的配置文件,以下提供shell脚本例子,适当修改即可:

#/bin/bash
网站文件所在目录:
find ./  -maxdepth 1 -type d -name "*.com"  | sed 's#.\/#\/var\/www\/html\/#' > /root/mulu.txt
find ./  -maxdepth 1 -type d -name "*.net"  | sed 's#.\/#\/var\/www\/html\/#' >> /root/mulu.txt
find ./  -maxdepth 1 -type d -name "*.org"  | sed 's#.\/#\/var\/www\/html\/#' >> /root/mulu.txt
find ./  -maxdepth 1 -type d -name "*.cn"  | sed 's#.\/#\/var/\www\/html\/#' >> /root/mulu.txt


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

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

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

    }
EOF
done
Exit mobile version