Unable to use load_module
Closed this issue · 3 comments
Hi,
I need to include the geoip2 module.
I've tried to place it in /etc/nginx/geoip.conf like this
load_module modules/ngx_http_geoip2_module.so;
load_module modules/ngx_stream_geoip2_module.so;
geoip_country /etc/nginx/GeoLite2-Country.mmdb {
$geoip_country_code default=US source=$remote_addr country iso_code;
}
However, I get this error:
frontend-nginx-proxy | forego | starting nginx.1 on port 32200
frontend-nginx-proxy | nginx.1 | nginx: [emerg] "load_module" directive is not allowed here in /etc/nginx/conf.d/geoip.conf:1
There's this other issue on this topic which was never resolved: #1535
Thank you for the help.
Hi @frnzhop
That's weird, I don't understand where your geoip.conf is included from, there is nothing in the upstream image or in the nginx.tmpl file that should include it by default. 🤔
Have you modified anything else ?
Hi,
thank you for your answer. I'm replying from this other account since I don't have access to the other one rn.
You're right, I should've mentioned the path /etc/nginx/geoip.conf was just my convention.
I solved it by mounting a modified nginx.conf in /etc/nginx/nginx.conf with the following content:
load_module modules/ngx_http_geoip_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /run/nginx.pid;
events {
worker_connections 10240;
}
worker_rlimit_nofile 20480;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
geoip_country /etc/nginx/geoip/GeoIP.dat;
geoip_city /etc/nginx/geoip/GeoLiteCity.dat;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
include /etc/nginx/toplevel.conf.d/*.conf;However, with my solution I won't get updates to the nginx.conf file.
Is there a better way to customize nginx core directives in general?
Thank you.
That's the solution I was about to suggest, and sadly no at the moment there isn't any other way to customize nginx core directives other than mounting your own /etc/nginx/nginx.conf to the container.
However I wouldn't worry so much about missing updates to the nginx.conf file, I'm not event sure I witnessed changes to it in the years I've been maintaining this repo.
Interestingly I can't trace this file origin, it's not on the docker-nginx repo and does not match the one on the nginx repo (which was last updated 12 years ago). Maybe generated when nginx is built 🤷 ?