【发布时间】:2022-02-11 19:35:08
【问题描述】:
我正在尝试通过向我的 dockerfile 添加以下内容,通过 dockerfile 为 nginx 安装 geoip 模块:
RUN apk add --no-cache libmaxminddb nginx-mod-http-geoip
RUN cd /var/lib; \
mkdir -p nginx; \
wget -q -O- https://dl.miyuru.lk/geoip/maxmind/country/maxmind.dat.gz | gunzip -c > nginx/maxmind-country.dat; \
wget -q -O- https://dl.miyuru.lk/geoip/maxmind/city/maxmind.dat.gz | gunzip -c > nginx/maxmind-city.dat; \
chown -R nginx. nginx
COPY nginx.conf /etc/nginx/nginx.conf
nginx.config 如下:
load_module "modules/ngx_http_geoip_module.so";
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events{worker_connections 1024;
}
# See blow link for Creating NGINX Plus and NGINX Configuration Files
# https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format kv 'site="$server_name" server="$host" dest_port="$server_port" dest_ip="$server_addr" '
'src="$remote_addr" src_ip="$realip_remote_addr" user="$remote_user" '
'time_local="$time_local" protocol="$server_protocol" status="$status" '
'bytes_out="$bytes_sent" bytes_in="$upstream_bytes_received" '
'http_referer="$http_referer" http_user_agent="$http_user_agent" '
'nginx_version="$nginx_version" http_x_forwarded_for="$http_x_forwarded_for" '
'http_x_header="$http_x_header" uri_query="$query_string" uri_path="$uri" '
'http_method="$request_method" response_time="$upstream_response_time" '
'cookie="$http_cookie" request_time="$request_time" category="$sent_http_content_type" https="$https"'
'geoip_country_name="$geoip_country_name"';
access_log /var/log/nginx/access.log kv;
sendfile on;
keepalive_timeout 65;
geoip_country /var/lib/nginx/maxmind-country.dat;
geoip_city /var/lib/nginx/maxmind-city.dat;
include /etc/nginx/conf.d/*.conf;
# The identifier Backend is internal to nginx, and used to name this specific upstream
upstream backend {
# dashboard is the internal DNS name used by the backend Service inside Kubernetes
server localhost:5005;
}
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location /api/ {
resolver 127.0.0.11; #nginx will not crash if host is not found
# The following statement will proxy traffic to the upstream
proxy_pass http://backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
但是,当我检查我得到的日志时
geoip_country_name = "-"
知道这里出了什么问题吗?难道是我在本地运行这个?
【问题讨论】:
-
"-"是日志文件在值为空时使用的内容。 GeoIP 使用$remote_addr来计算国家。那么日志条目中src="$remote_addr"的值是什么,它给了您geoip_country_name = "-",您应该能够确定它是您的代理问题还是您的数据库问题。 -
@RichardSmith src="172.17.0.1" 的值。
标签: nginx dockerfile nginx-location geoip