天天看點

Random Index

nginx顯示随機首頁子產品(Random Index)

前言

一般情況下,一個站點預設首頁都是定義好的index.html、index.shtml、index.php等等,如果想站點下有很多頁面想随機展示給使用者浏覽,那得程式上實作,顯得尤為麻煩,如果你安裝了nginx,那麼使用nginx的random index即可達成這個功能,凡是以/結尾的請求,都會随機展示目前目錄下的檔案作為首頁.

random index介紹

ngx_http_random_index_module子產品處理以'/'為字尾的請求,并且在目前目錄下随機抽取一個頁面作為首頁.這個子產品将在ngx_http_index_module子產品之前執行. 預設情況下,這個子產品沒有安裝,你需要在安裝nginx的時候加上配置參數--with-http_random_index_module.

随機首頁配置

1

2

3

location / {

 random_index on;

 }

random index指令

文法: random_index on | off;

預設值: random_index off;

配置段: location

繼續閱讀