记静态服务数据迁移,含nginx、html、https配置。详细可参考.bash_history
打包项目
1 2 3 4 5 6 7
| zip data.zip xxx/
zip nginx.zip /usr/local/nginx
scp -r data.zip nginx.zip [user]@[ip]:[path]
|
最耗时的步骤
新服务器配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
vim /usr/lib/systemd/system/nginx.service
wget https://raw.githubusercontent.com/certbot/certbot/7f0fa18c570942238a7de73ed99945c3710408b4/letsencrypt-auto-source/letsencrypt-auto -O certbot-auto
chmod 755 certbot-auto
./certbot-auto certonly --standalone --email [email] -d [域名] -d [www.域名]
systemctl start nginx.service
|
至此,项目已全部迁移成功,详细过程可参考~/.bash_history
文件
Nginx配置说明
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| server { rewrite ^(.*) https://[域名] permanent;
location ~* ^.+\.(webp|jpg|jpeg|gif|png|ico|css|js|pdf|txt){ expires 30d; access_log off;
gzip on; gzip_http_version 1.1; gzip_buffers 16 8k; gzip_comp_level 6; gzip_min_length 1k; gzip_types image/webp application/pdf text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_proxied any; root path; } }
|
Github Hook配置
Github配置位置,项目的Settings->Webhooks->Add webhook
。填写对应的信息
- Payload URL: 域名+端口(flask服务配置)
- Content type:json
- Secret:自定义密钥,在脚本中配置
- Which events would you like to trigger this
webhook?:仅在推送时进行操作
服务器上的python脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| from flask import Flask, request import os import sys from pprint import pprint import hmac app = Flask(__name__)
repo_path = '' secret = ''
def encryption(data): key = secret.encode('utf-8') obj = hmac.new(key, msg=data, digestmod='sha1') return obj.hexdigest()
@app.route("/", methods=["GET", "POST"]) def hello(): post_data = request.data token = encryption(post_data) signature = request.headers.get('X-Hub-Signature', '').split('=')[-1] if signature != token: return 'failed'
os.system('cd {} && git pull'.format(repo_path)) return 'success'
if __name__ == "__main__": app.run(host="0.0.0.0", port=port)
|
若推送失败,可在服务器手动git pull
,或者在webhook
地址,[Recent Deliveries]
中进行Redeliver