Skip to content

Instantly share code, notes, and snippets.

@mateor
Last active March 25, 2016 14:41
Show Gist options
  • Select an option

  • Save mateor/4938d1cb521b19ef889e to your computer and use it in GitHub Desktop.

Select an option

Save mateor/4938d1cb521b19ef889e to your computer and use it in GitHub Desktop.
nginx conf used by Foursquare's artifact cache
# NOTE: 2 cpu cores
worker_processes 2;
error_log /data/log/nginx/error.log;
events {
# NOTE: Accept as many connections as possible, after nginx gets notification about a new connection.
# May flood worker_connections, if that option is set too low.
multi_accept on;
# NOTE: ulimit -n
worker_connections 63536;
}
http {
upstream backend {
hash $request_uri consistent;
server ${SERVER1};
server ${SERVER2};
server ${SERVER3};
}
client_max_body_size 1g;
server {
listen 80;
server_name localhost;
proxy_request_buffering off;
# NOTE(this is the response)
proxy_buffering off;
location / {
# NOTE: Set current host in order to possibly redirect a GET request in the upstream.
proxy_set_header Pants-Proxy-Host $hostname;
proxy_pass http://backend;
}
}
server {
listen 8080;
server_name localhost;
client_body_temp_path /data/appdata/nginx/tmp 1 2;
create_full_put_path on;
dav_access group:rw all:r;
dav_methods PUT DELETE;
sendfile on;
location / {
# HACK: Nginx doesn't support logical operators.
# The below code is equivalent to
# `if (http_pants_proxy_host != NULL && $request_method = GET && $downStreamProxy != $hostname)`
if ($request_method = GET) {
set $downStreamProxy $http_pants_proxy_host;
}
if ($http_pants_proxy_host = '') {
set $downStreamProxy $hostname;
}
if ($request_method = HEAD) {
set $downStreamProxy $hostname;
}
if ($request_method = PUT) {
set $downStreamProxy $hostname;
}
if ($downStreamProxy != $hostname) {
return 307 http://$hostname:$server_port$request_uri;
}
root /data/appdata/nginx/pantscache;
autoindex on;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment