Nethence Newdoc Olddoc Lab Your IP BBDock  

NGINX fancy directory listing from scratch

make sure you got the build essential packages, PCRE, zlib and openssl libs,

apt install build-essential libpcre3-dev zlib1g-dev libssl-dev

fetch latest NGINX source and proceed with custom compilation,

git clone
tar xzf nginx-1.13.0.tar.gz
cd nginx-1.13.0/
./configure --with-http_addition_module --with-http_ssl_module --add-module=../ngx-fancyindex

and install the compiled package,

#make install
apt install checkinstall

then setup the thing with fancy headers & footers into the http or server context,

cd ~/
ln -s /usr/local/nginx

cd ~/nginx/html/
rm -f index.html 50x.html
echo '<p>header' > header.html
echo '<p>footer' > footer.html
touch file

cd ~/nginx/conf/
vi nginx.conf

#ls -lhF ~/nginx/modules/
#(main context) -- using static module, no need
#load_module modules/;

#root already defined

autoindex on;

location / {
    try_files $uri $uri/ =404;
    fancyindex on; # Enable fancy indexes.
    fancyindex_exact_size off; # Output human-readable file sizes.
    fancyindex_header /header.html;
    fancyindex_footer /footer.html;
    fancyindex_ignore favicon.ico robots.txt header.html footer.html css;
    fancyindex_localtime off;

move your configs to the right place (do NOT use existing /etc/nginx/conf.d/ as dpkg –purge might remove those),

mkdir /usr/local/nginx/etc/conf.d/
mv /etc/nginx/conf.d/* /usr/local/nginx/etc/conf.d/
vi /usr/local/nginx/etc/conf/nginx.conf

user www-data;
worker_processes  auto;

events {
    worker_connections  1024;

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen  80;
        listen  [::]:80;
        server_name _;
        return 301;

    include /usr/local/nginx/etc/conf.d/*.conf;

make sure the system vendor NGINX is NOT currently in use,

dpkg -l | grep nginx
ps aux | grep nginx
netstat -antupe --inet --inet6 | grep nginx

and finally run the thing,

cd ~/
/usr/local/nginx/sbin/nginx -V
ls -lhF /usr/local/nginx/logs/

enable it at boot time and on Ubuntu 16+, make sure the System D service for rc-local is enabled at boot time and don’t forget to make the script executable,

vi /etc/rc.local


echo -n starting custom nginx...
/usr/local/nginx/sbin/nginx && echo done
#/usr/local/nginx/sbin/nginx -s reload

systemctl status rc-local.service
chmod +x /etc/rc.local

eventually get rid of the distro package (be careful with purge, assuming /etc/nginx/ is cleaned-up!),

apt purge nginx
apt autoremove
dpkg -l | grep ^rc
dpkg --purge ...

note. to run as Docker container on foreground,

nginx -g 'daemon off;'


Home | GitHub | Donate | Contact