Skip to content

Instantly share code, notes, and snippets.

package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/cactus/go-statsd-client/statsd"
"io/ioutil"
"log"
"net/http"
http {
geo $subnet {
default 0;
45.55.0.0/24 1;
}
map $subnet $value {
default "";
1 $remote_addr;
@kmjones1979
kmjones1979 / json_log.conf
Created November 24, 2015 20:32
JSON Log format for NGINX
log_format json '{'
# disabled to use timestamp in iso8601 format
# '"time_local": "$time_local",'
'"time_iso8601": "$time_iso8601",'
'"browser": ['
'{'
'"modern_browser": "$modern_browser",'
'"ancient_browser": "$ancient_browser",'
'"msie": "$msie"'
'}'
@kmjones1979
kmjones1979 / nginx.conf
Last active March 3, 2024 06:41
Example NGINX configuration to do service routing based on headers
events { worker_connections 2014; }
http {
include /etc/nginx/conf.d/*.conf;
default_type text/plain;
error_log /var/log/nginx/example_debug_error.log debug;
access_log /var/log/nginx/example_access.log;
@kmjones1979
kmjones1979 / nginx.conf
Created April 14, 2016 20:18
Example NGINX configuration to dynamically set the local IP address during socket creation
# Example of proxy_bind using variables using split_clients and map
events { worker_connections 2014; }
http {
default_type text/plain;
error_log /var/log/nginx/debug_error.log debug;
server {
@kmjones1979
kmjones1979 / nginx.conf
Last active November 16, 2017 12:04
Example NGINX configuration to perform A/B deployments
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {
default_type text/html;
log_format main '$remote_addr -> $request $status $body_bytes_sent bytes -> $upstream_addr';
access_log /var/log/nginx/access.log main;
@kmjones1979
kmjones1979 / nginx.conf
Last active January 18, 2024 17:25
Example NGINX configuration using auth_request and auth_request_set directives to route users
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {
default_type text/html;
log_format main '$remote_addr -> $request $status $body_bytes_sent bytes -> $upstream_addr';
access_log /var/log/nginx/access.log main;
@kmjones1979
kmjones1979 / nginx.conf
Last active October 1, 2023 15:50
Example NGINX configuration to route based on country code using GeoIP
# load dynamic modules
load_module /etc/nginx/modules/ngx_http_geoip_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events { worker_connections 1024; }
http {
@kmjones1979
kmjones1979 / nginx.conf
Created June 2, 2016 21:12
NGINX configuration used for MaxCDN meetup demonstration in Los Angeles 2016
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
@kmjones1979
kmjones1979 / nginx.conf
Last active June 6, 2016 16:57
map argument to new variable with NGINX
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}