Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Forked from amitsaha/nginx.conf
Created September 1, 2020 21:46
Show Gist options
  • Save amanjuman/73b0dfd2e153ddd0fb64d2dcb7ff0e1d to your computer and use it in GitHub Desktop.
Save amanjuman/73b0dfd2e153ddd0fb64d2dcb7ff0e1d to your computer and use it in GitHub Desktop.
nginx conf + geoip2
# blog post: https://echorand.me/nginx-and-geoip2.html
worker_processes auto;
daemon off;
error_log /dev/stdout warn;
include /etc/nginx/modules/*.conf;
load_module modules/ngx_http_geoip2_module.so;
events {
}
http {
geoip2 /etc/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code default=US source=$http_x_forwarded_for country iso_code;
$geoip2_data_country_name source=$http_x_forwarded_for country names en;
}
geoip2 /etc/GeoLite2-City.mmdb {
$geoip2_data_city_name source=$http_x_forwarded_for city names en;
$geoip2_data_time_zone source=$http_x_forwarded_for location time_zone;
}
server_tokens off;
default_type application/octet-stream;
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request_method":"$request_method",'
'"request":"$request",'
'"response_status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"real_ip": "$http_x_forwarded_for",'
'"geoip_country_code": "$geoip2_data_country_code",'
'"geoip_country_name": "$geoip2_data_country_name",'
'"geoip_city": "$geoip2_data_city_name",'
'"geoip_timezone": "$geoip2_data_time_zone"'
'}';
access_log /dev/stdout json_combined;
server {
location / {
root /content/;
}
}
}
user nginx;
worker_processes auto;
pcre_jit on;
daemon off;
error_log /dev/stdout warn;
include /etc/nginx/modules/*.conf;
load_module modules/ngx_http_geoip2_module.so;
events {
use epoll;
worker_connections 2048;
}
http {
map $http_x_forwarded_for $realip {
~^(\d+\.\d+\.\d+\.\d+) $1;
default $remote_addr;
}
geoip2 /etc/GeoLite2-Country.mmdb {
auto_reload 5m;
$geoip2_metadata_country_build metadata build_epoch;
$geoip2_data_country_code source=$realip country iso_code;
$geoip2_data_country_name source=$realip country names en;
}
geoip2 /etc/GeoLite2-City.mmdb {
$geoip2_data_city_name source=$realip city names en;
$geoip2_data_time_zone source=$realip location time_zone;
}
server_tokens off;
include /etc/nginx/mime.types;
include /etc/nginx/custom_configs/gzip_settings;
include /etc/nginx/custom_configs/map_params;
default_type application/octet-stream;
client_max_body_size 100m;
keepalive_timeout 65;
sendfile on;
tcp_nodelay on;
upstream php {
server 127.0.0.1:9000;
}
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request_method":"$request_method",'
'"request":"$request",'
'"response_status": "$status",'
'"body_bytes_sent":"$body_bytes_sent",'
'"request_time":"$request_time",'
'"http_referrer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"real_ip": "$realip",'
'"geoip_country_code": "$geoip2_data_country_code",'
'"geoip_country_name": "$geoip2_data_country_name",'
'"geoip_city": "$geoip2_data_city_name",'
'"geoip_timezone": "$geoip2_data_time_zone"'
'}';
access_log /dev/stdout json_combined;
include /etc/nginx/conf.d/*.conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment