Nginx method to add the ngx fancyindex module

  • 2020-05-14 06:09:01
  • OfStack

To be on the safe side, Nginx list is not allowed in the default directory on the whole, namely when accessing a directory does not include the front page will return a 403 error, when we need the server directory listing 1 indexes in order to download, we can use autoindex, but autoindex module to generate the index is very humble, we can use ngx - fancyindex instead of autoindex index catalog beautification.

This article is for operations in the installed Nginx environment.

Install ngx - fancyindex

Step 1

View the installed Nginx version and module information:


nginx -V

The output information is similar to:

[

nginx version: nginx/1.8.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx

]

Step 2

Download the corresponding version of Nginx source package: http: / / nginx org/download /

Package: download the latest version of ngx - fancyindex source https: / / github com aperezdc/ngx - fancyindex/releases

Upload to the server and unzip, here we upload to /tmp directory.

Step 3

Compile Nginx


cd /tmp/nginx-1.8.0 # Go to source directory  
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --user=nginx --group=nginx --add-module=../ngx-fancyindex-0.4.2
make  # compile 

Special note:

The configuration after./configure should correspond to the output information of step 1 to prevent unnecessary trouble. / ngx-fancyindex-0.4.2 here according to the ngx-fancyindex directory name you downloaded and unzipped. You only need make, you don't need install.

Step 4

Rename the old nginx file:


mv /usr/local/nginx /usr/local/nginx.bak

Copy the recompiled nginx file to the original nginx installation directory:


cp ./objs/nginx /usr/local/nginx/sbin/

Restart nginx service:


service nginx restart

Configuration ngx - fancyindex

Modify the nginx configuration file


location /path/ # The specified ~/path Directory opens the automatic column directory 
{
 alias /alliot/path/; # Virtual directory /alliot/path/ Open the automatic column directory 
 root /path/;  # The actual directory /path/ Open the automatic column directory   with alias2 choose 1
 fancyindex on;  # open nginx Directory browsing function  
 fancyindex_exact_size off; # File size from KB Began to show  
 fancyindex_localtime on; # Display file modification time as server local time  
 fancyindex_footer "footer.html"; # Set up the footer For the current directory footer.html
 fancyindex_ignore "footer.html"; # Setting does not list items in the current directory footer.html
}

The difference between alias and root above is that alias specifies the current directory, while root specifies the root directory. In general, it is recommended to configure the root directory through the root command in "location/".

See more configuration https: / / github com/aperezdc/ngx - fancyindex

reload

perform


nginx -s reload

Related articles: