Total Pageviews

Friday 8 July 2016

一个基于python的静态博客程序- IceHoney-BLOG

先安装依赖:
pip install tornado
pip install markdown
然后git clone https://github.com/acgotaku/IceHoney-BLOG icehoney-blog
cd icehoney-blog

root@AR:~/icehoney-blog# ls
application.py handlers  posts  README.md  static  tpl
root@AR:~/icehoney-blog# cd posts
root@AR:~/icehoney-blog/posts# nano 2016-07-08-test1.markdown
root@AR:~/icehoney-blog/posts# cat 2016-07-08-test1.markdown
---
layout: post
title: "测试1"
date: 2016-07-08 15:03
comments: true
tags: misc
---

这是测试1.(此处写正文或html code)
root@AR:~/icehoney-blog/posts# ls
...
2016-05-05-WebGL-render.markdown
2016-06-30-webpack.markdown
2016-07-08-chinese-economy.markdown
2016-07-08-test1.markdown
2016-07-08-test2.markdown
2016-07-08-test3.markdown
2016-07-08-tfair-disaster.markdown
root@AR:~/icehoney-blog/posts# cd ..
root@AR:~/icehoney-blog# nohup python application.py > /dev/null &

新建帖子并保存后,网站就自动更新了。

注意:源帖在服务器里的posts目录里是按字母顺序(从a到z)和数字顺序(从小到大)从上到下排列的,排在最下面
的帖子就显示在网页的最上面。所以我写的一个最新的源贴(空中浩劫),本来我是把源贴文件写为
2016-07-08-air-disaster.markdown的,但那样的话,此源贴文件就不是排在posts目录的最下面而是排在
2016-07-08-chinese-economy.markdown文件的上面,这样的话,该帖子就不会显示在网页的最上面而是显示在
2016-07-08-chinese-economy.markdown文件所对应的帖子的下面。为了让最新的源贴所对应的帖子
显示在网页的最上面,就需要修改2016-07-08-air-disaster.markdown的文件名,使它在posts目录里,排在
2016-07-08-test3.markdown的下面,于是我把2016-07-08-air-disaster.markdown的文件名改为了
2016-07-08-tfair-disaster.markdown,f排在e之后,所以在posts目录里,
2016-07-08-tfair-disaster.markdown就会排在2016-07-08-test3.markdown的下面。

root@AR:~/icehoney-blog/posts# cd ..
root@AR:~/icehoney-blog# ls
application.py handlers  posts  README.md  static  tpl
root@AR:~/icehoney-blog# nano application.py

把第9行的127.0.0.1改为0.0.0.0,把第10行的8888改为9999,(我服务器的8888端口之前已被占用),访问http://your_vps_ip:9999即可看到网站效果。
演示站点:http://surmount.biz.st:9999,你可设置一个反向代理以去掉(9999)端口。nginx/apache都有设置反向代理的功能。建议用nginx做反向代理。apache做反向代理不太好用。

项目地址:https://github.com/acgotaku/IceHoney-BLOG
类似的项目: https://github.com/MartianZ/MartianZ-BLOG,
这2个项目太相似了。估计IceHoney-BLOG是fork自MartianZ-BLOG,然后修改了一番。
(参见http://briteming.blogspot.com/2016/03/pythonmartianz-blog.html)

附录:
在你的服务器上安装nginx webserver,然后修改nginx.conf如下,添加如下的server段:
server {
  listen       80;
  server_name  example.com;
  location / {
     root   /usr/share/nginx/html/;
     proxy_pass http://localhost:9999/;
     proxy_redirect off;
     proxy_set_header X-Forwarded-Host $host;
     proxy_set_header X-Forwarded-Server $host;
     proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

重启nginx,访问http://example.com,即可访问到http://surmount.biz.st:9999的内容。
我添加的域名为smt.biz.st,所以访问http://smt.biz.st,即可访问到http://surmount.biz.st:9999的内容。
参考http://www.thegeekstuff.com/2016/06/nginx-reverse-proxy-to-apache/