Fix nginx: [emerg] “load_module” directive is specified too late

How to solve nginx error "load_module" directive is specified too late when updating software dependencies

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.

nginx: [emerg] "load_module" directive is specified too late

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,

cd /etc/nginx/modules-enabled

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[1]: 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[17247]: 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[17247]: nginx: configuration file /etc/nginx/nginx.conf test failed
Dec 19 03:02:17 32ram320gb8core systemd[1]: nginx.service: Control process exited, code=exited status=1
Dec 19 03:02:17 32ram320gb8core systemd[1]: nginx.service: Failed with result 'exit-code'.
Dec 19 03:02:17 32ram320gb8core systemd[1]: 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.

Tharindu

Hey!! I'm Tharindu. I'm from Sri Lanka. I'm a part time freelancer and this is my blog where I write about everything I think might be useful to readers. If you read a tutorial here and want to hire me, contact me here.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

We use cookies to give you the best online experience. By agreeing you accept the use of cookies in accordance with our cookie policy.