分享一个自己建的shell指创建网站和数据库;
因为不会用lnmp命令写在里面创建,所以就用了一个比较笨的方法;先用lnmp vhost add生成一个网站配置文件,然后利用这个修改一下,写成for循环的shell;
把二级域名放在了list.txt里面,生成的就是a0001.xxx.cn这样的;#!/bin/bash
#
for i in `cat list.txt`;do
echo "server
{
listen 80;
#listen [::]:80;
server_name a$i.xxxx.cn ;
index index.html index.htm index.php default.html default.htm default.php;
root/home/www/demo/a$i;
include none.conf;
#error_page 404 /404.html;
# Deny access to PHP files in specific directory
#location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }
include enable-php.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /.well-known {
allow all;
}
location ~ /\.
{
deny all;
}
access_log off;
}
" > /usr/local/nginx/conf/vhost/a$i.xxxx.cn.conf
mkdir -p /home/www/demo/a$i
done
exit然后数据库是在phpmyadmin里面,新建一个数据库,把命令拷出来,用for循环,自动添加;里面的密码是加密后的,你可以先添加一个数据库,然后把里面的密码拷出来,放在shell里面;#!/bin/bash
for i in `cat list.txt`; do
mysql -uroot -ppassword -e "CREATE USER 'a$i'@'localhost' IDENTIFIED WITH mysql_native_password;"
mysql -uroot -ppassword -e "GRANT USAGE ON *.* TO 'a$i'@'localhost' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;"
mysql -uroot -ppassword -e "set password for 'a$i'@'localhost'= '*3F8050F5B6A9EE2107F82662C50E420C00181465';"
mysql -uroot -ppassword -e "CREATE DATABASE IF NOT EXISTS a$i;"
mysql -uroot -ppassword -e "GRANT ALL PRIVILEGES ON a$i.* TO 'a$i'@'localhost';"
done
页:
[1]