最近團隊在搞前端創新,準備引入一些新技術,在同事發的郵件中,看到了淘寶基於nginx開發的靜態服務器——Tengine。在「one company」的理念下,公司靜態服務器頗有可能從獨角獸切換到Tengine。如今提早研究下。 css
對前端而言,Tengine能帶來什麼? html
* 合併多個CSS、JavaScript文件的訪問請求變成一個請求;
* 強制GZip壓縮; 前端
以上2點對一個前端來講,就已經頗有吸引了,不是麼? nginx
Tengine在2011年末,已經成爲一個開源項目。更多介紹能夠參考下官網。
官網傳送門:http://tengine.taobao.org/index_cn.html
本人的機器是ubuntu,因此下面的安裝步驟就是ubuntu的安裝步驟了。 git
1.安裝tegine編譯庫 gcc, zlib1g-dev, libpcre3, libpcre3-dev這些庫文件是必須的,會沒辦法編譯tegine
ubuntu安裝命令:
apt-get install gcc libpcre3 libpcre3-dev zlib1g-dev github
2.獲取tegine,能夠經過git或直接下載tar包
(1)克隆源代碼:Git clone https: https://github.com/taobao/tengine ~/tengine
(2)安裝包地址:http://tengine.taobao.org/download/tengine-1.3.0.tar.gz ubuntu
3.編譯安裝 服務器
cd ~/tengine
./configure --with-http_concat_module --with-http_sysguard_module --with-http_stub_status_module
make
make install
.net
--with-http_concat_module 開啓concat模塊,合併文件模塊
更多編譯的幫助參考下面2個文檔:
nginx 編譯參數詳解:http://blog.lizhigang.net/archives/137
淘寶tengine文檔:http://tengine.taobao.org/documentation_cn.html cdn
4.修改配置文件
vi /usr/local/nginx/conf/nginx.conf
修改對應的location配置:
location /
{
root /home/beihe/work;
concat on; //開啓合併功能
autoindex on; //容許列出整個目錄,nginx默認不列出文件列表
autoindex_exact_size off; //顯示出文件的大概大小,單位是kB或者MB或者GB,若是是on,單位是bytes
autoindex_localtime on; //顯示的文件時間爲GMT時間
}
5.tengine基本命令
/usr/local/nginx/sbin/nginx 啓動
/usr/local/nginx/sbin/nginx -s reload 重啓
/usr/local/nginx/sbin/nginx -s stop 關閉
啓動nginx的用戶可能沒有nginx,logs目錄訪問權限,可能會有下面提示錯誤:
could not open error log file:
open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)2011/03/21 06:09:33 [emerg] 24855#0:
mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)
解決辦法:
sudo chmod a+rwx -R logs
sudo chmod a+rwx -R /usr/local/nginx
6.啓動tengine,體驗concat合併功能。 concat功能能夠在服務器端合併多個文件,好比你要下面三個js文件 http://a.tbcdn.cn/p/fp/2012/fp/layout.css http://a.tbcdn.cn/p/fp/2012/fp/dpl/dpl.css http://a.tbcdn.cn/p/fp/2012/fp/sitenav/sitenav.css 只須要經過下面一個連接,就能夠得到上面3個css文件,而且合併事後的文件gzip壓縮的。 http://a.tbcdn.cn/p/fp/2012/fp/??layout.css,dpl/dpl.css,sitenav/sitenav.css,logo/logo.css?t=2012080220120724.css