手工部署 Zmirror 镜像

部署环境

  • 一台国外 VPS
  • Ubuntu 14.04
  • Apache

安装步骤

初始化环境

  • 我在安装过程当中让升级 grub2, 我选择不不升级(应该怎么选都不影响)
sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime &&
sudo apt-get update &&
sudo apt-get upgrade -y &&
sudo apt-get dist-upgrade -y &&
sudo apt-get install build-essential patch binutils make devscripts nano libtool libssl-dev libxml2 libxml2-dev software-properties-common python-software-properties dnsutils git wget curl python3 python3-pip iftop -y &&
sudo python3 -m pip install -U flask requests cchardet fastcache

安装 Apache2

LC_ALL=C.UTF-8 sudo add-apt-repository -y ppa:ondrej/apache2 &&
sudo apt-key update &&
sudo apt-get update &&
sudo apt-get upgrade -y &&
sudo apt-get install apache2 -y &&
sudo a2enmod rewrite mime include headers filter expires deflate autoindex setenvif ssl http2 &&
sudo apt-get install libapache2-mod-wsgi-py3 -y

安装 zmirror - Google

  • 假设将 zmirror 安装到 /var/www/zmirror ,本教程以部署 Google 镜像为例,即 使用这个配置文件more_configs/config_google_and_zhwikipedia.py
cd /var/www &&
git clone https://github.com/aploium/zmirror &&
cd zmirror &&
chown -R www-data . && 
chgrp -R www-data . &&
cp more_configs/config_google_and_zhwikipedia.py config.py

配置 zmirror - Google

须要手动修改 config.py, 在里面加上本身的域名python

  • 在大约第 38 行开始处, 的
# ############## Local Domain Settings ##############
my_host_name = '127.0.0.1'
my_host_scheme = 'http://'
  • 修改成以下, 修改两行, 添加一行
    • 请将其中的g.caisan.ml替换为你是本身实际的域名
    • 新添加的 verbose_level = 2 这一行, 把 zmirror 的日志级别设置为Warning, 减小日志产生量.
    • 默认是 3 级, 会产生大量 debug 日志
# ############## Local Domain Settings ##############
my_host_name = 'g.caisan.ml'
my_host_scheme = 'https://' # 注意把上面这行的http改为https
verbose_level = 2

安装 let's encrypt 并得到证书

  • 证书来源
    本教程使用 let's encrypt 证书, 获取很是快, 可是有效期只有 90 天, 到期前须要从新获取
    请将下面脚本中 g.caisan.ml 域名修改成你本身的域名, 修改后能直接复制进去运行
    为保证兼容性, 本教程使用 standalone 模式获取证书, 因此须要先停掉 apache(包含在下面脚本中了)
sudo service apache2 stop &&
cd ~ &&
git clone https://github.com/certbot/certbot &&
cd certbot &&
./certbot-auto certonly --agree-tos -t --standalone -d g.caisan.ml
  • 生成的证书存储在/etc/letsencrypt/live/g.caisan.ml/

配置 Apache2

cd /etc/apache2/conf-enabled &&
wget https://gist.githubusercontent.com/aploium/8cd86ebf07c275367dd62762cc4e815a/raw/29a6c7531c59590c307f503b186493e559c7d790/h5.conf

设置网站配置文件

  • 而后进入/etc/apache2/sites-enabled文件夹,建立一个google.conf文件, 内容以下 (记得修改对应的域名和文件夹等东西)
<IfModule mod_ssl.c>
    SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
    <VirtualHost *:443>
        # 域名, 记得修改为你本身的
        ServerName g.caisan.ml
        # 这个没用的
        ServerAdmin root@localhost

        # 下面两个log文件路径也建议按实际修改
        # 默认保存在 /var/log/apache2/ 文件夹下
        # ErrorLog 中包含了zmirror产生的stdout输出, 若须要debug能够看它
        ErrorLog ${APACHE_LOG_DIR}/zmirror-google_ssl_error.log
        CustomLog ${APACHE_LOG_DIR}/zmirror-google_ssl_access.log combined

        # ##### WSGI 这部分是重点  ######
        WSGIDaemonProcess zmirror_google user=www-data group=www-data threads=16
        #这是刚刚安装的zmirror的路径
        WSGIScriptAlias / /var/www/zmirror/wsgi.py
        WSGIPassAuthorization On

        # 给予zmirror文件夹权限
        <Directory /var/www/zmirror>
            WSGIProcessGroup zmirror_google
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
        </Directory>

       # ######### SSL部分 这部分告诉Apache你的证书和私钥在哪 #########
       # 下面使用的是刚刚let's encrypt给咱们的证书, 你也能够用别的
        SSLEngine on
        # 私钥
        SSLCertificateFile /etc/letsencrypt/live/g.caisan.ml/cert.pem
        # 证书
        SSLCertificateKeyFile /etc/letsencrypt/live/g.caisan.ml/privkey.pem
        # 证书链
        SSLCertificateChainFile /etc/letsencrypt/live/g.caisan.ml/chain.pem

       # HTTP/2
        <IfModule http2_module>
            Protocols h2 h2c http/1.1
        </IfModule>
    </VirtualHost>
</IfModule>

重启 Apache2

sudo service apache2 restart

设置重定向

  • /etc/apache2/sites-enabled/000-default.conf 中加入如下设置, 使得 HTTP 能自动跳转到 HTTPS
    • 加在<VirtualHost> </VirtualHost>括起来范围的里面
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</IfModule>
相关文章
相关标签/搜索