Enable Directory Listing in Nginx

I switched from Apache to Nginx a few months ago and have been learning many things.  One recent task I encountered was how to enable directory listing of a directory when an index file was not present.

This is what I typically see by default when trying to view a path that does not contain an index file in Nginx webserver.

Nginx’s HttpAutoIndexModule handles this.

Auto indexing can be enabled in http, server or location context.  I specifically wanted to allow auto indexing on only a particular subdirectory of my website.

I opened up Nginx’s configuration for the site I’m using which was found in /etc/nginx/sites-enabled/techish.net.conf

Under the http context, I created a location context and told it to use auto indexing if it did not find an index file.

location /pub/test {
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

autoindex on – turns auto indexing on
autoindex_exact_size off – I want file sizes rounded (KB, MB, GB, etc.). The default is off which uses Bytes.
autoindex_localtime on – Enables the file times to be shown locally. By default this is disabled and uses GMT.

A quick reload of Nginx and then I browse to https://techish.net/pub/test and directory browsing is working. No more 403 Forbidden errors.

W: GPG error: The following signatures couldn't be verified because the public key is not available

W: GPG error: http://nginx.org squeeze Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY ABF5BD827BD9BF62

Resolution

1.  gpg --keyserver pgpkeys.mit.edu --recv-key THEKEY
2.  gpg -a --export THEKEY | apt-key add -
root@node1:~# gpg --keyserver pgpkeys.mit.edu --recv-key ABF5BD827BD9BF62
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key 7BD9BF62 from hkp server pgpkeys.mit.edu
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key 7BD9BF62: public key "nginx signing key " imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
root@node1:~# gpg -a --export ABF5BD827BD9BF62 | apt-key add -
OK

Check for configuration errors with FAM/Gamin Library

Popup in Outlook and webmail:

Your IMAP server wants to alert you to the following: filesystem notification initialization error — contact your mail administrator (check for configuration errors with the FAM/Gamin library)

I have a Courier IMAP+SASL+Maildrop+Postfix+MySQL setup.
I don’t know what the root problem is; I just know things have been working until recently updating the system (which inevitably broke something).

root@node1:# apt-cache search fam gamin
gamin - File and directory monitoring system
libgamin-dev - Development files for the gamin client library
libgamin0 - Client library for the gamin file and directory monitoring system
python-gamin - Python binding for the gamin client library
kdelibs4c2a - core libraries and binaries for all KDE applications
root@node1:# apt-get install gamin
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  sensible-mda tnef sendmail-cf sendmail-base daemon libnet-cidr-lite-perl
  clamav-daemon
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libgamin0 libglib2.0-0 libglib2.0-data shared-mime-info
The following packages will be REMOVED:
  libfam0
The following NEW packages will be installed:
  gamin libgamin0 libglib2.0-0 libglib2.0-data shared-mime-info
0 upgraded, 5 newly installed, 1 to remove and 32 not upgraded.
Need to get 3072 kB of archives.
After this operation, 10.5 MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Get:1 http://ftp.us.debian.org/debian/ squeeze/main libglib2.0-0 amd64 2.24.2-1 [1122 kB]
Get:2 http://ftp.us.debian.org/debian/ squeeze/main libgamin0 amd64 0.1.10-2+b1 [42.3 kB]
Get:3 http://ftp.us.debian.org/debian/ squeeze/main gamin amd64 0.1.10-2+b1 [72.9 kB]
Get:4 http://ftp.us.debian.org/debian/ squeeze/main libglib2.0-data all 2.24.2-1 [994 kB]
Get:5 http://ftp.us.debian.org/debian/ squeeze/main shared-mime-info amd64 0.71-4 [841 kB]
Fetched 3072 kB in 2s (1085 kB/s)
dpkg: libfam0: dependency problems, but removing anyway as you requested:
 courier-base depends on libfam0.
 courier-imap depends on libfam0.
(Reading database ... 31853 files and directories currently installed.)
Removing libfam0 ...
Selecting previously deselected package libglib2.0-0.
(Reading database ... 31845 files and directories currently installed.)
Unpacking libglib2.0-0 (from .../libglib2.0-0_2.24.2-1_amd64.deb) ...
Selecting previously deselected package libgamin0.
Unpacking libgamin0 (from .../libgamin0_0.1.10-2+b1_amd64.deb) ...
Selecting previously deselected package gamin.
Unpacking gamin (from .../gamin_0.1.10-2+b1_amd64.deb) ...
Selecting previously deselected package libglib2.0-data.
Unpacking libglib2.0-data (from .../libglib2.0-data_2.24.2-1_all.deb) ...
Selecting previously deselected package shared-mime-info.
Unpacking shared-mime-info (from .../shared-mime-info_0.71-4_amd64.deb) ...
Processing triggers for man-db ...
Setting up libglib2.0-0 (2.24.2-1) ...
Setting up libglib2.0-data (2.24.2-1) ...
Setting up shared-mime-info (0.71-4) ...
Setting up gamin (0.1.10-2+b1) ...
Setting up libgamin0 (0.1.10-2+b1) ...
root@node1:# /etc/init.d/courier-imap restart
Stopping Courier IMAP server: imapd.
Starting Courier IMAP server: imapd.
root@node1:# /etc/init.d/courier-imap
courier-imap      courier-imap-ssl
root@node1:# /etc/init.d/courier-imap-ssl restart
Stopping Courier IMAP-SSL server: imapd-ssl.
Starting Courier IMAP-SSL server: imapd-ssl.
root@node1:# dpkg -l |grep -i libfam|gamin
ii  gamin                               0.1.10-2+b1                  File and directory monitoring system
rc  libfam0                             2.7.0-17                     Client library to control the FAM daemon
ii  libgamin0                           0.1.10-2+b1                  Client library for the gamin file and directory monitoring system

libfam0:

Description: Client library to control the FAM daemon
FAM monitors files and directories, notifying interested applications
of changes.
.
This package provides a shared library to allow programs to connect to
the FAM daemon and ask for files to be monitored.
Homepage: http://oss.sgi.com/projects/fam/

gamin

Description: File and directory monitoring system
Gamin is a file and directory monitoring system which allows
applications to detect when a file or a directory has been added,
removed or modified by somebody else.
.
It can be used by desktops like KDE, GNOME or Xfce to have their
virtual file systems keep track of changes to files and directories.
For example, if a file manager displays a directory to the user, and
the user removes one of the files via the command-line, gamin will
notify the file manager of this change so that it can update the
directory display.
.
Gamin has been designed as a drop-in replacement for FAM with security
and maintainability in mind and can use Linux’s advanced inotify
service when available.

All I know is things work again. I’ll dig into this some other day. In with the new out with the old.