顯示隨機(jī)首頁模塊(Random Index)
一般情況下,一個(gè)站點(diǎn)默認(rèn)首頁都是定義好的index.html、index.shtml、index.php等等,如果想站點(diǎn)下有很多頁面想隨機(jī)展示給用戶瀏覽,那得程序上實(shí)現(xiàn),顯得尤為麻煩,如果你安裝了nginx,那么使用nginx的random index即可達(dá)成這個(gè)功能,凡是以/結(jié)尾的請(qǐng)求,都會(huì)隨機(jī)展示當(dāng)前目錄下的文件作為首頁.
random index介紹
ngx_http_random_index_module模塊處理以'/'為后綴的請(qǐng)求,并且在當(dāng)前目錄下隨機(jī)抽取一個(gè)頁面作為首頁.這個(gè)模塊將在ngx_http_index_module模塊之前執(zhí)行. 默認(rèn)情況下,這個(gè)模塊沒有安裝,你需要在安裝nginx的時(shí)候加上配置參數(shù)--with-http_random_index_module.
隨機(jī)首頁配置
location / { random_index on; } random index指令
語法: random_index on | off;
默認(rèn)值: random_index off;
配置段: location
啟用或者禁用random index模塊
生成空白圖片(empty_gif模塊)
用過百度統(tǒng)計(jì)的兄弟有沒有注意到百度使用1x1的空白圖片傳遞統(tǒng)計(jì)參數(shù),自己做異步統(tǒng)計(jì)的兄弟是否使用靜態(tài)文件來傳遞參數(shù)。為什么使用空白圖片呢,而不是自己存放一張小圖呢,nginx里面的空白圖片是保存在內(nèi)存中的,速度絕對(duì)比硬盤上讀取的快. 看下如何使用empty_gif生成響應(yīng)1x1的空白圖片吧.
nginx默認(rèn)內(nèi)置ngx_http_empty_gif_module模塊, 如何安裝nginx我不在多講.直接看下empty_gif的用法
nginx配置
nginx模塊ngx_http_empty_gif_module會(huì)響應(yīng)1x1的GIF圖片.
location = /_.gif { empty_gif;} 如下是我的nginx配置
server { listen 80; server_name test.ttlsa.com; access_log /data/logs/nginx/test.ttlsa.com.access.log main; index index.html index.php index.html; root /data/site/test.ttlsa.com; location ~* /3145/ { empty_gif; }} 測(cè)試empty_gif
訪問test.ttlsa.com/3145/結(jié)果如下:
empty_gif指令
語法: empty_gif;
默認(rèn): —
配置段: location
開啟響應(yīng)1x1空白圖片
最后
empty_gif用得最多的地方還是統(tǒng)計(jì),當(dāng)然你覺得可以用的地方也是可以用,只要是你用得著,畢竟內(nèi)存速度比硬盤要快非常多.




















