标签:ups rman sys ddr gen 需要 bash poll 别名
提供isp服务的都知道,托管用户的网站,用户需要将域名解析过来,一般提供个别名地址给用户解析。但是有的域名解析平台不带www的不能做cname解析,这时候需要告知用户将不带www的域名解析到特定的服务器上,这里称为301重定向服务器。301重定向服务器将不带www的访问永久从定向到www上。
1,环境准备
我这里使用tengine,主配制文件为
user nginx;
worker_processes auto;
worker_cpu_affinity auto;
error_log logs/error.log info;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 8192;
}
http {
server_tokens off;
gzip on;
include mime.types;
default_type application/octet-stream;
log_format proxy ‘$remote_addr $server_addr $remote_user [$time_local] $status $body_bytes_sent ‘
‘$request_time "$request" "$http_referer" "$http_user_agent" "$request_body" ‘
‘$upstream_addr $upstream_status $upstream_response_time $upstream_cache_status $http_host‘;
access_log logs/access.log proxy;
#cache
client_header_buffer_size 512k;
large_client_header_buffers 8 128k;
client_max_body_size 128m;
sendfile on;
tcp_nopush on;
keepalive_timeout 300;
#proxy
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_temp_path temp;
proxy_buffer_size 64k;
proxy_buffers 16 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 256k;
proxy_max_temp_file_size 0;
proxy_cache_path cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=3g;
proxy_ignore_client_abort on;
#naxsi
#include naxsi/naxsi_core.rules;
#waf
#lua_package_path "/usr/local/tengine/conf/waf/?.lua";
#lua_shared_dict limit 50m;
#init_by_lua_file /usr/local/tengine/conf/waf/init.lua;
#access_by_lua_file /usr/local/tengine/conf/waf/waf.lua;
#include vhost
include vhost/*.conf;
}
可以看到我们的配置是在vhost/*.conf这里。
那么这个配置如何生成呢。我写了一个脚本
#!/bin/bash
#
# Description: This is sysytem optimization scripts about centos !
################################################################
# Author:tommy xiao
# QQ: 610000107
# Date: 2019.06.28
################################################################
for i in `cat /root/301/301list.txt`;do
cat >> /root/301/301.txt <<EOF
###${i}###
if (\$http_host ~ "^${i}\$") {
rewrite ^(.*) https://www.${i}\$1 permanent;
}
EOF
if [ $? -eq 0 ];then
echo -e "\033[40;32m"$i" Configuration Successful!!!\n\033[40;37m"
else
echo -e "\033[40;31m"$i" configuration failed!!!\n\033[40;37m"
fi
done
# Variable settings
conffile="/usr/local/tengine/conf/vhost/301.conf"
date=`date +%Y%m%d%H%M%S`
/bin/mv $conffile $conffile.$date
cat > $conffile <<EOF
server {
}
EOF
sed -i ‘1 r /root/301/301.txt‘ /usr/local/tengine/conf/vhost/301.conf
if [ $? -eq 0 ];then
service nginx reload && rm -rf /root//301/301.txt
else
echo -e "\033[40;31mUpdate configuration failed!!!\n\033[40;37m"
exit 1
fi
1,将需要添加301重定向的域名一行一行的写在/root/301/301list.txt
这个文件里
2,按照301重定向配置的格式将所有域名写入到/root//301/301.txt文件里
3,重命名配置文件301.conf
4,重新生存新的配置文件301.conf,将server配置写进去
server {
}
5,将/root//301/301.txt里的所有内容写入到301.conf的server里
6,重启服务器
编写一个监控脚本,监控到301list.txt有新增域名,则重新生成行配置。
#!/bin/bash
md5new=`md5sum /root/301/301list.txt | awk ‘{print $1}‘`
md5old=`cat /root/301/301.md5`
date=`date +%Y%m%d%H%M%S`
if [ $md5new == $md5old ];then
echo "$md5new $date" >> /root/301/chmd5.txt
else
/bin/bash /root/301/301.sh
echo "$md5new" > /root/301/301.md5
fi
1,301list.txt这文件可以直接编辑添加
2,写个程序,通过在页面上输入域名,点击提交,然后更新到这个文件里去。添加一个更新按钮,主动去执行这个监测脚本。(这个写好在贴上来)
标签:ups rman sys ddr gen 需要 bash poll 别名
原文地址:https://blog.51cto.com/7585527/2419662