创建个人网站主机配置文件,
先设置几个域名的虚拟主机,
,让所有请求 gehaowu.com,www.gehaowu.com 两个域名的 http 请求,强制跳转到 https 协议的 www.gehaowu.com ,
接着一个对发给 gehaowu.com 的 https 请求也强制转发给 www.gehaowu.com 。
关闭日志记录。
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
server { listen 80; listen [::]:80; server_name gehaowu.com www.gehaowu.com; add_header Strict-Transport-Security max-age=31536000; if ($http_user_agent !~* baidu.com) { rewrite ^/(.*) https://www.gehaowu.com/$1 permanent; } index index.html; root /home/ghw/wwwroot; error_page 404 /404.html; error_page 403 /403.html; error_page 500 502 503 504 /50x.html; access_log /home/ghw/wwwlog/baidu.access.log; error_log /home/ghw/wwwlog/baidu.error.log; }
server { listen 443 ssl spdy; listen [::]:443 ssl spdy; server_name gehaowu.com; ssl_certificate keys/www.gehaowu.com.crt; ssl_certificate_key keys/www.gehaowu.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA256:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EDH+aRSA+AESGCM:EDH+aRSA+SHA256:EDH+aRSA:EECDH:!DH:!aNULL:!eNULL:!MEDIUM:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security max-age=31536000; ssl_session_cache shared:SSL:5m; ssl_session_timeout 5m; ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate keys/www.gehaowu.com.crt; resolver 8.8.4.4 8.8.8.8; rewrite ^/(.*) https://www.gehaowu.com/$1 permanent; }
server { listen 443 ssl spdy; listen [::]:443 ssl spdy ipv6only=on; server_name www.gehaowu.com; ssl_certificate keys/www.gehaowu.com.crt; ssl_certificate_key keys/www.gehaowu.com.key; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+ECDSA+AESGCM:EECDH+aRSA+AESGCM:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA256:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:EECDH+aRSA+SHA384:EDH+aRSA+AESGCM:EDH+aRSA+SHA256:EDH+aRSA:EECDH:!DH:!aNULL:!eNULL:!MEDIUM:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS:!RC4:!SEED; ssl_prefer_server_ciphers on; add_header Strict-Transport-Security max-age=31536000; ssl_session_cache shared:SSL:5m; ssl_session_timeout 5m; ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate keys/www.gehaowu.com.crt; resolver 8.8.4.4 8.8.8.8; index index.html; root /home/ghw/wwwroot; error_page 404 /404.html; error_page 403 /403.html; error_page 500 502 503 504 /50x.html; access_log /home/ghw/wwwlog/www.gehaowu.com.access.log; error_log /home/ghw/wwwlog/www.gehaowu.com.error.log;
location = /bookcase { return 301 /bookcase/; } location ^~ /bookcase { proxy_pass https://gehaowu.github.io; proxy_set_header Host gehaowu.github.io; proxy_set_header X-Host gehaowu.github.io; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} location = /life { return 301 /life/; } location ^~ /life { proxy_pass https://gehaowu.github.io; proxy_set_header Host gehaowu.github.io; proxy_set_header X-Host gehaowu.github.io; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
location ~ /\. { deny all; }
location ~* ^/(favicon.ico|robots.txt|status.gif)$ { allow all; access_log /dev/null; error_log /dev/null; }
location ~* \.(html|htm|xml|rss|atom|txt|xhtml)$ { expires 1d; }
location ~* \.(css|gif|jpeg|jpg|js|png|ico|bmp|svg|doc|pdf|mp3|ogg|mp4|mpeg|webm|eot|ttf|woff)$ { expires 7d; } }
|

新建一个网站根目录, 比如我这里使用 /home/ghw/ ,接着执行 gitclone.sh 文件
首次 clone 用的 gitclone.sh 脚本
1 2 3 4 5 6
| #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin git clone --depth 1 -b gh-pages https://github.com/gehaowu/www.gehaowu.com /home/ghw/wwwroot git clone --depth 1 -b gh-pages https://github.com/gehaowu/aboutme /home/ghw/wwwroot/aboutme git clone --depth 1 -b gh-pages https://github.com/gehaowu/notes /home/ghw/wwwroot/notes git clone --depth 1 -b gh-pages https://github.com/gehaowu/albums /home/ghw/wwwroot/albums
|

因为我在 wwwroot 根目录放了 gitpull.sh 脚本,所以直接给 cron 添加计划任务:
让 crontab 每 5 个小时执行一次 pull 脚本
1 2
| * */5 * * * /bin/sh /home/ghw/wwwroot/gitpull.sh >/dev/null 2>&1
|

gitpull.sh 脚本的内容
因为 blog 模块实际上会出现向github提交的时候会使用-f参数,所以我们下拉的时候需要先清理掉分支
1 2 3 4 5 6 7 8 9 10 11 12 13
| #!/bin/sh PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin export LC_ALL=zh_CN.UTF-8 date >> /home/ghw/gitpulldate.log cd /home/ghw/wwwroot/ git pull cd /home/ghw/wwwroot/aboutme/ git pull cd /home/ghw/wwwroot/notes/ git pull git reset --hard cd /home/ghw/wwwroot/albums/ git pull
|
搞完,这样就可以了,
没五个小时从 github 上拉取网站数据,所以我们只需要将自己的网站数据同步到github上就可以了。。。
十分容易也十分安全,哈哈哈。。。<( ̄▽ ̄)>
版权声明

Ge Haowu’s Personal Website by Haowu Ge is licensed under a CC BY-NC-ND 4.0 International License.
由 葛豪武 创作并维护在葛豪武的个人网站 采用 署名-非商业性使用-禁止演绎 创意共享 4.0 国际 许可证。
本文首发于 葛豪武的个人网站!· Ge Haowu’s Personal Website! ,版权所有,侵权必究。