Total Pageviews

Tuesday, 11 February 2014

在linux vps上搭建基于go的静态博客程序-trofaf


as3:~# cd ~/mygo
as3:~/mygo# go get github.com/PuerkitoBio/trofaf
as3:~/mygo# cd ~/mygo/src/github.com/PuerkitoBio/trofaf
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# git clone https://github.com/PuerkitoBio/0value
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# ls 0value
posts public sass templates
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# mv 0value/* ./
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# ls
examples gen_test.go main.go public rss.go server.go tpldata.go
gen.go LICENSE posts README.md sass templates watch.go
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# cd posts
as3:~/mygo/src/github.com/PuerkitoBio/trofaf/posts# nano test1.md
test1.md的格式如下:
---
Title: test1
Date: 2014-02-12T17:40:00-08:00
---

这是测试1.
as3:~/mygo/src/github.com/PuerkitoBio/trofaf/posts# cd ..
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# trofaf -g (这个就是更新静态网站的命令)
as3:~/mygo/src/github.com/PuerkitoBio/trofaf# ls public
agora-v0-2--closures--coroutines-and-for--range
build-a-blog-engine-in-Go
build-a-restful-API-with-Martini
css
favicon.ico
font
img
implementing-lua-coroutines-in-Go
index.html
introducing-agora--a-dynamic--embeddable-programming-language-built-with-Go
my-Go-centric-Vim-setup
rss
test1
as3:~/mygo/src/github.com/PuerkitoBio/trofaf#
(~/mygo/src/github.com/PuerkitoBio/trofaf/public/里有index.html,可见
~/mygo/src/github.com/PuerkitoBio/trofaf/public/就是静态网站的根目录。)

我绑定了域名tf.brite.biz到~/mygo/src/github.com/PuerkitoBio/trofaf/public/,不过访问
http://tf.brite.biz/test1时,浏览器显示的是html文件的源码内容:
<!DOCTYPE html><!-- From HTML5 Boilerplate -->
<html class="no-js" lang="en">
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>测试3</title>
        <meta name="description" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <link rel="stylesheet" href="/css/main.css" />
        <link rel="alternate" href="http://localhost/rss" type="application/rss&#43;xml" title="RSS" />
        <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.2/html5shiv.js"></script>
    </head>
    <body>
...

这个问题的解决办法:在~/mygo/src/github.com/PuerkitoBio/trofaf/public/里面放一个.htaccess即可,
.htaccess的内容为:
DefaultType text/html
(参考:http://stackoverflow.com/questions/9142117/pages-are-displaying-plain-text-instead-of-html/21717903#21717903,
顺便参见:http://serverfault.com/questions/336376/apache-serving-html-files-as-text
http://xhtml.com/en/xhtml/media-types-how-the-web-works/)

不放.htaccess也行,只要在virtualhost段里加上一行:
 DefaultType text/html也可。如果是nginx webserver,则在nginx的配置文件的相应的server段里加上default_type text/html;即可。参见
http://forum.nginx.org/read.php?11,201491

演示站点:http://tf.brite.biz/
项目地址:https://github.com/PuerkitoBio/trofaf