This is an error I encountered while trying to run regular maintenance on a customer VPS. The VPS was running Jitsi Meet, a self-hosted video conferencing software. Nginx was configured to proxy connections to Jitsi on port 4444 back and forth. Let’s see how to fix nginx: [emerg] “load_module” directive is specified too late error on Ubuntu 18.04.
I tried to update packages using apt update and apt upgrade. Following was the error I got on the command terminal. And obviously, update failed and nginx failed to start.
The error is related to the load_module directive that loads geoip module which is required by Jitsi Meet. Looking at the nginx modules directory, you can see that files are numbered.
As you can see from the above screenshot, Jitsi Meet module comes before geoip modules. Solution is to change the order. We can do it by renaming 60-jitsi-meet.conf to 80-jitsi-meet.conf. So logged in as the root user, let’s navigate to nginx modules-enabled directory,
Now use mv command to rename the file.
mv 60-jitsi-meet.conf 80-jitsi-meet.conf
Now restart nginx
service nginx restart
Doing so will make nginx error nginx: [emerg] “load_module” directive is specified too late disappear. You can now go ahead and complete the VPS update.
Although this post discuss about a VPS with Jitsi Meet and the error is how what related to Jitsi itself, I’ve seen the error nginx: [emerg] “load_module” directive is specified too late popping up time to time in other environments as well. So if you ever came a cross it, paying attention to nginx modules enabled directory is a good idea.
If you’re not able to troubleshoot it yourself, you can ask for help in our server administration support forums. I will try my best to help resolve it. Following is the nginx startup error recorded on logs.
Dec 19 03:02:16 32ram320gb8core systemd: Starting A high performance web server and a reverse proxy server... -- Subject: Unit nginx.service has begun start-up -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- Unit nginx.service has begun starting up. Dec 19 03:02:17 32ram320gb8core nginx: nginx: [emerg] "load_module" directive is specified too late in /etc/nginx/modules-enabled/70-mod-stream-geoip.conf:1 Dec 19 03:02:17 32ram320gb8core nginx: nginx: configuration file /etc/nginx/nginx.conf test failed Dec 19 03:02:17 32ram320gb8core systemd: nginx.service: Control process exited, code=exited status=1 Dec 19 03:02:17 32ram320gb8core systemd: nginx.service: Failed with result 'exit-code'. Dec 19 03:02:17 32ram320gb8core systemd: Failed to start A high performance web server and a reverse proxy server. -- Subject: Unit nginx.service has failed -- Defined-By: systemd -- Support: http://www.ubuntu.com/support -- -- Unit nginx.service has failed. -- -- The result is RESULT.