nginx

NGINX load_module error - How to load modules from an include file?


I have defined a settings for nginx server

load_module /etc/nginx/modules-enabled/50-mod-http-image-filter.conf;
include load_modules.include;

# the upstream component nginx needs to connect to
http { upstream educa {
    server      unix:///tmp/educa.sock;
}


server {
    listen       80;
    server_name  www.educaproject.com educaproject.com;
    access_log   off;
    error_log    /home/anton/Course-system/educa/config/logs/nginx_error.log;
    location / {
        include      /etc/nginx/uwsgi_params;
        uwsgi_pass   educa;
    }
}}

However, using the command, i got error
'sudo nginx nginx: [emerg] dlopen() "/etc/nginx/modules-enabled/50-mod-http-image-filter.conf" failed (/etc/nginx/modules-enabled/50-mod-http-image-filter.conf: file too short) in /home/anton/Course-system/educa/config/nginx.conf:1

Text of load_ 50-mod-http-image-filter.conf file is "module modules/ngx_http_image_filter_module.so";


Solution

  • You have to define all load_module directives directly in the nginx.conf OR with an include file that will be included and have the load_module directives you want. The load_module directive is only allowed in the main-configuration context. Make sure all your load_module statements are defined there:

    user  nginx;                                                  
    worker_processes  auto;                                       
                                                                  
    error_log  /var/log/nginx/error.log warn;                     
    pid        /var/run/nginx.pid;                                
                                                                  
    
    include /etc/nginx/modules-enabled/50-mod-http-image-filter.conf;
                                                                  
    events {                                                      
        worker_connections  1024;                                 
    }                                                             
                                                                  
                                                                  
    http {   
    ....
    }
                                                     
    

    ProTip: I name all special includes not *.conf because that gives me more control on how and where to include them. I can still use something like include *.conf later in my http block without breaking anything.