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
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
/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
须要手动修改 config.py
, 在里面加上本身的域名python
# ############## Local Domain Settings ############## my_host_name = '127.0.0.1' my_host_scheme = 'http://'
g.caisan.ml
替换为你是本身实际的域名verbose_level = 2
这一行, 把 zmirror 的日志级别设置为Warning
, 减小日志产生量.# ############## Local Domain Settings ############## my_host_name = 'g.caisan.ml' my_host_scheme = 'https://' # 注意把上面这行的http改为https verbose_level = 2
g.caisan.ml
域名修改成你本身的域名, 修改后能直接复制进去运行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/
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>
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>