12

Using nginx/1.4.1 with OpenBSD 5.4, 64bit:

enter image description here

How could we set nginx to show the full filename (or at least show more from the filename then the default) when using directory listing?

Googling around only gave me this:

http://forum.nginx.org/read.php?2,124400,167420#msg-167420
January 18, 2011 08:36PM
fagtron
I looked all over the net and wasn't able to find this answer anyway, so I looked into the nginx source files and it's very easy.

Simply modify the file located at [b]src/http/modules/ngx_http_autoindex_module.c[/b] and then compile.

Change these lines:

[b]#define NGX_HTTP_AUTOINDEX_PREALLOCATE 50

#define NGX_HTTP_AUTOINDEX_NAME_LEN 50[/b]

to whatever you want, such as:

[b]#define NGX_HTTP_AUTOINDEX_PREALLOCATE 100

#define NGX_HTTP_AUTOINDEX_NAME_LEN 100[/b]

And then compile and restart nginx. That's it !!!

Question: are there no other way then to recomplie it?

evachristine
  • 2,603
  • 10
  • 39
  • 55
  • here is a manual, how to modify the nginx source: https://www.tecklyfe.com/nginx-display-full-filename-directory-listing/ – rubo77 Feb 08 '19 at 10:55

4 Answers4

7

You can try fancyindex module with its fancyindex_name_length parameter to configure the filename length.

Jack Rowe
  • 71
  • 1
  • 1
  • 2
    this should be the accepted answer. note that `fancyindex_name_length` is not mentioned on the nginx page but is on the module's github page. note that this module is included in the `nginx-extras` package. – w00t Mar 15 '18 at 20:27
5

According to ngx_http_autoindex_module documentation, configuration of column width for autoindexed pages is not available. Compiling from the source would be the only way to make this change.

One alternative could be to use a scripting language (e.g. php, ruby, or python) to perform the directory listing for you.

Benefits include:

  • fully customizable via CSS, JavaScript, etc
  • fine control over file listing

Caveats:

  • requires a CGI e.g. php-fpm or passenger
  • requires more configuration
ssh2ksh
  • 420
  • 4
  • 9
1

Since there seems no way to achieve this than compiling nginx from the source this would be a workaround:

You can automatically create an index.html file in the current folder, that contains the whole path, with this script:

#!/bin/bash
# scriptname: /usr/local/sbin/directory-long-index.sh
# 
# the directory_root without slash at the end:
WEB=/var/www/
#reacheable url from inside the server:
URL=http://localhost

P=$(pwd|sed "s|$WEB/||")
echo "download $URL/$P/ to index.html"
curl "$URL/$P/" -o index.html
sed -i 's|href="\(.*\)".*</a>|style="display:inline-block;min-width:500px" href="\1">\1</a>|' index.html

inside the folder just call:

source /usr/local/sbin/directory-long-index.sh

source: https://gist.github.com/rubo77/c7a9434eb104c00bf8772b2278284360


Another workaround would be to create a simple directory listing from scratch with

for i in *; do echo '<a href="'$i'">'$i'</a><br>'>>index.html; done
rubo77
  • 27,777
  • 43
  • 130
  • 199
  • This isn't even remotely related to the user's question. – pgoetz Jan 14 '17 at 13:49
  • 1
    Sure it is. It is a workaround you can use if you don't want to compile nginx from source – rubo77 Jan 14 '17 at 18:02
  • Sorry about that; on first reading I failed to realize that this is intended as an a priori step to be run on the server. Of course this will litter your directory structure with index.html files and needs to be re-run any time the underlying filesystem changes, but you are nevertheless correct. – pgoetz Jan 15 '17 at 14:10
0

Try this,

autoindex on;
autoindex_format json; # <- configure like this, your will get full name, FORMAT IN JSON

Document from Module ngx_http_autoindex_module

alswl
  • 137
  • 3