-
-
Save markjaquith/e567c81060178663b238 to your computer and use it in GitHub Desktop.
Nginx host config
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
server { | |
listen 80; | |
server_name example.com; | |
access_log /var/log/nginx/access.log main; | |
root /srv/www/example.com; | |
index index.html index.htm index.php; | |
location ~ \.(jpe?g|gif|png|css|bmp|js|ico)$ { | |
expires 30d; | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
# redirect server error pages to the static page /50x.html | |
# | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root /var/www/nginx-default; | |
} | |
location ~ /\.ht[a-z]+$ { | |
deny all; | |
} | |
location ~ \.php$ { | |
# Set some proxy cache stuff | |
fastcgi_cache microcache_fpm; | |
fastcgi_cache_key $scheme$host$request_method$request_uri; | |
fastcgi_cache_valid 200 5s; | |
fastcgi_cache_use_stale updating; | |
fastcgi_max_temp_file_size 1M; | |
fastcgi_cache_min_uses 3; # Hit a URL 3 times before caching it | |
set $no_cache_set 0; | |
set $no_cache_get 0; | |
set $temp_caching_exemption 0; | |
if ($request_method !~ ^(GET|HEAD)$) { | |
set $temp_caching_exemption 1; | |
} | |
if ( $temp_caching_exemption = 1 ) { | |
add_header Set-Cookie "_mcnc=1; Max-Age=10; Path=/"; | |
} | |
# Bypass cache if no-cache cookie is set | |
if ( $http_cookie ~* "_mcnc" ) { | |
set $no_cache_set 1; | |
set $no_cache_get 1; | |
} | |
if ( $http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) { | |
set $no_cache_set 1; | |
set $no_cache_get 1; | |
} | |
# fastcgi_no_cache means "Do not store this proxy response in the cache" | |
fastcgi_no_cache $no_cache_set; | |
# fastcgi_cache_bypass means "Do not look in the cache for this request" | |
fastcgi_cache_bypass $no_cache_get; | |
include /etc/nginx/fastcgi_params; | |
fastcgi_index index.php; | |
try_files $uri =404; | |
fastcgi_pass phpfpm; | |
} | |
} |
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
# Obviously not the whole thing, but have this somewhere in the http{} block | |
upstream phpfpm { | |
server unix:/var/run/php5-fpm.sock; | |
} | |
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=microcache_fpm:30m max_size=1000m; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing this. It's almost the same as my config that I set up for wordpress. With even a 5s/10s microcache, the amount of hits an nginx/php-fpm/apc/wordpress site can handle is phenomenal!