Nginx: “Unknown directive […]” after upgrading to Ubuntu 18 LTS

After upgrading vom Ubuntu 16 to 18 LTS I ran into a rather unpleasant and apparently undocumented issue:

The same happened with my WebDAV and fancyindex modules on another server:

The reason why this is happening is that while upgrading Ubuntu my nginx-extras installation got replaced with an installation that includes these modules dynamically. Dynamic modules are relatively new to nginx and if you care for the long explanation follow this link. TL;DR: You can add modules to nginx without recompiling it and thus it does not include many modules by default anymore.

The solution is to include any of your installed modules that you need. The can usually be found in /usr/share/nginx/modules/.

Add your required include to /etc/nginx/nginx.conf at the top of the file above any brackets:

Finally make sure your configuration works by once again running “nginx -t” and then restart nginx with “service nginx restart”.