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>