主要还是近期有单说要做一个入口url,使得某些条件下访问会跳到A网站,某些条件下跳到B网站。而这个入口url是投放广告用到的url,目标用户访问会跳到B站,而监管访问会跳到A站。不考虑他们这样用的目的,来捣鼓下

知识点扫盲

可以先看后面的,再回过头来看这些名词什么意思

X级域名

baidu.com — 二级域名
map.baidu.com — 三级域名

斗篷AB站

一个网站,在网站里输入 whitePage(A站,给监管看的) offerPage( B 站,给目标用户看的)的链接,然后配置规则(根据国家过滤、根据设备过滤…等等,有许多功能),然后就能生成 php 代码,把 php 代码作为你的入口页代码即可

怕被封

由于用户是投放广告,所以怕因为某些规则被封禁,封禁可能是封二级域名,所以 A、B 站不能用同一个二级域名,但入口和 A 站可以同一个二级域名。然后就也怕 ip 被封,所以 A、B 站归属的服务器 ip 不能是同一个

步骤

  1. 买服务器,两台( A,B 站不建议用同一台服务器,据说是怕被封),腾讯云轻量服务器,欧美服务器最低 30 块钱一个月,配置基本够用

  2. 域名相关:
    2.1. 买域名,两个二级域名( A,B 站不建议同一个二级域名),简称 A.comB.com
    2.2. 配置域名解析。
    - 入口域名:entrance.A.com
    - A站域名:xxx.A.com
    - B站域名:xxx.B.com
    2.3. https 证书申请,腾讯云申请免费证书即可(不过一个号只能申请 50 个免费证书,以后满了再看吧)

  3. 服务器基础环境配置
    3.1. 买服务器时选 Linux Ubuntu 20.x 版本,不要 22.x 版本(有一些坑,想想都心疼)
    3.2. A服务器先安装 Apache (用于部署入口页和A站)

    sudo apt-get update
    sudo apt install apache2
    sudo systemctl start apache2 #开启服务
    sudo systemctl enable apache2 #开机自启动
    
    sudo apt install php-fpm php-mysql #安装php环境,php-mysql好像用不上,放着吧
    
    //查看当前php版本,安装apache的php模块
    php -v 
    sudo apt-get install libapache2-mod-php7.4
    
    //斗篷需要这个支持
    sudo apt-get install php-curl
    
    

    3.3. B服务器安装 nginx (用于部署B站,纯粹是用起来nginx比apache方便所以不选择apache)

    sudo apt-get update
    sudo apt install nginx
    sudo systemctl start nginx #启动Nginx服务
    sudo systemctl enable nginx #设置Nginx开机自启
    
  4. A服务器部署 apache 站点

    • 部署入口页:
    先将证书放入/etc/apache2/ssl/目录下
    /etc/apache2/ssl/entrance.A.com.crt
    /etc/apache2/ssl/entrance.A.com.key
    
    //然后创建网站配置文件
    vim /etc/apache2/sites-available/entrance.A.com.conf
    
    将以下内容复制上去,记得改域名、证书和网站路径
    
    <IfModule mod_ssl.c>
        <VirtualHost _default_:443>
            ServerAdmin webmaster@entrance.A.com
            ServerName entrance.A.com
            ServerAlias www.entrance.A.com
    
            DocumentRoot /home/ubuntu/web/entrance
            <Directory /home/ubuntu/web/entrance>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
                DirectoryIndex index.htm
            </Directory>
    
            SSLEngine on
            SSLCertificateFile      /etc/apache2/ssl/entrance.A.com.crt
            SSLCertificateKeyFile   /etc/apache2/ssl/entrance.A.com.key
    
            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
            </Directory>
    
            BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
            CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
            ErrorLog ${APACHE_LOG_DIR}/ssl_error.log
        </VirtualHost>
    </IfModule>
    
    • A站的生成(扒站)

    背景:A站本身就是给监管看的,所以不要求质量多好,基本上去复制一下别人的网站就可以了(看用户要求)
    方法:使用webCopy软件,输入要扒的网站,选择深度1层(不然可能会特别久),将扒下来的网站上传到服务器某个目录即可,一般是~/web/sell/

    • 部署A站:
    先将证书放入/etc/apache2/ssl/目录下
    /etc/apache2/ssl/sell.A.com.crt
    /etc/apache2/ssl/sell.A.com.key
    
    //然后创建网站配置文件
    vim /etc/apache2/sites-available/sell.A.com.conf
    
    将以下内容复制上去,记得改域名、证书和网站路径
    
    <IfModule mod_ssl.c>
        <VirtualHost _default_:443>
            ServerAdmin webmaster@sell.A.com
            ServerName sell.A.com
            ServerAlias www.sell.A.com
    
            DocumentRoot /home/ubuntu/web/sell
            <Directory /home/ubuntu/web/sell>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
                DirectoryIndex index.php
            </Directory>
    
            SSLEngine on
            SSLCertificateFile      /etc/apache2/ssl/sell.A.com.crt
            SSLCertificateKeyFile   /etc/apache2/ssl/sell.A.com.key
    
            <FilesMatch "\.(cgi|shtml|phtml|php)$">
                SSLOptions +StdEnvVars
            </FilesMatch>
            <Directory /usr/lib/cgi-bin>
                SSLOptions +StdEnvVars
            </Directory>
    
            BrowserMatch "MSIE [2-6]" \
                nokeepalive ssl-unclean-shutdown \
                downgrade-1.0 force-response-1.0
            CustomLog ${APACHE_LOG_DIR}/ssl_access.log combined
            ErrorLog ${APACHE_LOG_DIR}/ssl_error.log
        </VirtualHost>
    </IfModule>
    
    • 启用网站和调试
    //启用虚拟主机\启用ssl\重启Apache
    sudo a2ensite entrance.A.com.conf
    sudo a2ensite sell.A.com.conf
    sudo a2enmod ssl
    sudo a2enmod php7.4
    sudo systemctl restart apache2
    
    //看日志
    tail -f /var/log/apache2/ssl_error.log
    tail -f /var/log/apache2/error.log
    
  5. B服务器部署 nginx 静态站点

    先将证书放到/etc/nginx目录下
    /etc/nginx/xxx.B.com_bundle.crt
    /etc/nginx/xxx.B.com.key
    
    sudo vim /etc/nginx/nginx.conf
    

    添加以下内容

    # 这一段是为了将http 301 到 https
    server {
            listen 80;
            server_name *.B.com;
            return 301 https://$host$request_uri;
    }
    
    server {
            listen 443 ssl;
            server_name xxx.B.com;
            ssl_certificate xxx.B.com_bundle.crt;
            ssl_certificate_key xxx.B.com.key;
            ssl_session_timeout 5m;
            ssl_protocols TLSv1.2 TLSv1.3;
            ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
            ssl_prefer_server_ciphers on;
    
            location / {
                    add_header Cache-Control "no-cache";
                    root /home/ubuntu/web/sell;
                    index index.htm;
            }
    }
    
    //重启nginx
    sudo nginx -s reload
    

迁移服务器

有时候服务器被攻击,需要紧急迁移服务器,以A服务器迁移为例

  1. 在腾讯云将A服务器制作一个镜像
  2. 买一个新服务器,运用刚刚的镜像
  3. 创建一个可执行脚本,名为 quickDeploy,内容如下:
    #!/bin/bash
    
    # 检查参数数量
    if [ "$#" -ne 2 ]; then
        echo "Usage: $0 <sell_domain> <et_domain>"
        exit 1
    fi
    
    # 读取参数
    sell_domain=$1
    et_domain=$2
    
    # 执行命令
    cd /etc/apache2/sites-available/ || exit
    sudo cp et.digitalasset666.top.conf "$et_domain.conf"
    sudo sed -i '/Rewrite/d' "$et_domain.conf"
    sudo sed -i "s/et.digitalasset666.top/$et_domain/g" "$et_domain.conf"
    sudo cp sell.digitalasset666.top.conf "$sell_domain.conf"
    sudo sed -i '/Rewrite/d' "$sell_domain.conf"
    sudo sed -i "s/sell.digitalasset666.top/$sell_domain/g" "$sell_domain.conf"
    sudo a2ensite "$et_domain"
    sudo a2ensite "$sell_domain"
    sudo a2enmod ssl
    sudo a2enmod php7.4
    sudo systemctl restart apache2
    cd /etc/letsencrypt/renewal/ || exit
    sudo rm et.digitalasset666.top.conf
    sudo rm sell.digitalasset666.top.conf
    sudo certbot --apache -d "$et_domain" -d "$sell_domain"
    sudo certbot renew --dry-run
    sed -i "s/et.digitalasset666.top/$et_domain/g" ~/web/site0/index.php
    
    
  4. 执行 quickDeploy 新的入口页域名 新的A站域名

PS: 可根据实际情况,不执行脚本也行,根据实际情况执行命令