Last active
December 16, 2015 04:08
-
-
Save dctrwatson/5374973 to your computer and use it in GitHub Desktop.
Caching Nginx Conf for Phabricator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user www-data; | |
worker_processes 4; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
access_log off; | |
default_type application/octet-stream; | |
sendfile on; | |
tcp_nodelay on; | |
tcp_nopush off; | |
reset_timedout_connection on; | |
server_tokens off; | |
map $request_uri $no_cache { | |
default 1; | |
~^/file/data/ 0; | |
~^/file/xform/ 0; | |
~^/res/pkg/ 0; | |
} | |
# Cache up to 100G of responses and expire after 1 month of not being used | |
fastcgi_cache_path /var/lib/nginx/phab levels=1:2 keys_zone=phab:128m inactive=1M max_size=100G; | |
fastcgi_temp_path /var/lib/nginx/temp 1 2; | |
gzip on; | |
gzip_types application/json text/css text/javascript; | |
gzip_proxied any; | |
gzip_vary on; | |
client_max_body_size 100M; | |
server { | |
listen 80 default_server; | |
server_name phabricator.example.com; | |
root /opt/phabricator/webroot; | |
location / { | |
expires max; | |
try_files $uri /index.php?__path__=$uri&$query_string; | |
} | |
location ~ ^/res/[a-f0-9]+(/.*) { | |
expires max; | |
try_files $1 /index.php?__path__=$uri&$query_string; | |
} | |
location = /index.php { | |
if ($args !~ __path__) { | |
set $args __path__=$uri&$query_string; | |
} | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
# Only cache responses according to map $no_cache | |
fastcgi_no_cache $no_cache; | |
fastcgi_cache_bypass $no_cache; | |
fastcgi_cache_key $request_uri; | |
fastcgi_cache phab; | |
# Cache 200 301 302 for 1M | |
fastcgi_cache_valid 1M; | |
# Respond with stale if updating cache or some errors | |
fastcgi_cache_use_stale error timeout updating http_500 http_503; | |
# Prevent stampede for same resource to backend | |
fastcgi_cache_lock on; | |
# Ignore caching headers from phab | |
fastcgi_ignore_headers Expires Cache-Control; | |
fastcgi_pass unix:/tmp/phabricator.sock; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment