利用fancyindex美化OpenWrt/LEDE的nginx目錄索引界面


nginx開啟目錄索引很簡單,在http {}內添加如下幾行:

autoindex on;
autoindex_exact_size off; #顯示換算后的文件大小,KB/MB等
autoindex_localtime on;   #時間

默認配置下,nginx的目錄索引是長這樣的

丑不說,字還特別小,這怎么忍?必應搜索"nginx 索引美化",第一篇就是關於怎么編譯Fancyindex這個nginx模塊,但是OpenWrt的編譯選項中並沒有這個。繼續搜,找到用自帶HTTP_ADDITION模塊添加自定義樣式的,感覺能行,但是nginx -V檢查后並沒有編譯這個模塊,而且編譯選項同樣沒有。

首先OpenWrt的源碼中是不含有nginx源碼的,編譯時會從官網下載源碼,官網的源碼肯定可以添加HTTP_ADDITION模塊,但是OpenWrt少了一些模塊的選項。我嘗試在OpenWrt的源碼目錄中找nginx的Makefile,最后在feeds\packages\net\nginx里找到(如果沒有編譯過應該是沒有這個目錄的),打開看,文件內容大概如下

ADDITIONAL_MODULES:=

ifneq ($(BUILD_VARIANT),all-module)
  ifneq ($(CONFIG_NGINX_HTTP_CACHE),y)
    ADDITIONAL_MODULES += --without-http-cache
  endif
  ifneq ($(CONFIG_NGINX_PCRE),y)
    ADDITIONAL_MODULES += --without-pcre
  endif
  #接下來都是類似這樣
else
  CONFIG_NGINX_HEADERS_MORE:=y
  CONFIG_NGINX_HTTP_BROTLI:=y
  CONFIG_NGINX_RTMP_MODULE:=y
  CONFIG_NGINX_TS_MODULE:=y
  CONFIG_NGINX_NAXSI:=y
  CONFIG_NGINX_LUA:=y
  CONFIG_NGINX_DAV:=y
  CONFIG_NGINX_UBUS:=y
  ADDITIONAL_MODULES += --with-http_ssl_module --add-module=$(PKG_BUILD_DIR)/nginx-naxsi/naxsi_src \
    --add-module=$(PKG_BUILD_DIR)/lua-nginx --with-ipv6 --with-http_stub_status_module --with-http_flv_module \
	--with-http_dav_module --add-module=$(PKG_BUILD_DIR)/nginx-dav-ext-module \
	--with-http_auth_request_module --with-http_v2_module --with-http_realip_module \
	--with-http_secure_link_module --with-http_sub_module --add-module=$(PKG_BUILD_DIR)/nginx-headers-more \
	--with-stream --with-stream_ssl_module --with-stream_ssl_preread_module \
	--add-module=$(PKG_BUILD_DIR)/nginx-brotli --add-module=$(PKG_BUILD_DIR)/nginx-rtmp \
	--add-module=$(PKG_BUILD_DIR)/nginx-ts --add-module=$(PKG_BUILD_DIR)/nginx-ubus-module
  config_files += koi-utf koi-win win-utf fastcgi_params uwsgi_params
endif

那么理論上我在if-else外層加上我需要的編譯選項,編譯出來的nginx就會帶有那些模塊,嘗試在endif下面加上一句代碼

ADDITIONAL_MODULES += --with-http_addition_module \ #HTTP_ADDITION模塊,fancyindex依賴這個模塊
  --add-module=/home/username/git/ngx-fancyindex #fancyindex模塊,從github拉取的源碼

編譯,再nginx -V

...--with-http_addition_module --add-module=/home/username/git/ngx-fancyindex...

一次通過,舒服
然后安裝主題到/www目錄,配置/etc/nginx/nginx.conf,加上

fancyindex on;
fancyindex_exact_size off;
fancyindex_header "/Nginx-Fancyindex-Theme-dark/header.html";
fancyindex_footer "/Nginx-Fancyindex-Theme-dark/footer.html";

再次打開索引頁面

效果還不錯,雖然配色有點單調


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM