Last active
March 11, 2016 17:10
-
-
Save evandhoffman/8ecb26d4d0082d18f808 to your computer and use it in GitHub Desktop.
nginx cache 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
proxy_cache_path /var/lib/nginx/cache/staticfiles levels=1:2 keys_zone=staticfilecache:10m max_size=50m; | |
proxy_cache_path /var/lib/nginx/cache/php levels=2:2 keys_zone=php:10m inactive=20m max_size=50m; | |
proxy_temp_path /var/lib/nginx/proxy; | |
proxy_connect_timeout 30; | |
proxy_read_timeout 120; | |
proxy_send_timeout 120; | |
#IMPORTANT - this sets the basic cache key that's used in the static file cache. | |
proxy_cache_key "$scheme://$host$request_uri"; |
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
# http://wp-performance.com/2010/10/nginx-reverse-proxy-cache-wordpress-apache/ | |
upstream apache { | |
server 127.0.0.1:8000; | |
# server 10.2.30.94:80; | |
} | |
server { | |
#Only cache 200 responses, and for a default of 20 minutes. | |
proxy_cache_valid 200 20m; | |
#Listen to your public IP | |
listen 80; | |
server_name _; | |
#Probably not needed, as the proxy will pass back the host in "proxy_set_header" | |
#server_name www.yoursite.com yoursite.com; | |
#access_log /var/log/nginx/yoursite.proxied.log; | |
# "combined" matches apache's concept of "combined". Neat. | |
access_log /var/log/nginx/combined-access.log combined; | |
# Set the real IP. | |
proxy_set_header X-Real-IP $remote_addr; | |
# Set the hostname | |
proxy_set_header Host $host; | |
#Set the forwarded-for header. | |
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header X-NginX-Proxy true; | |
location /evan/ { | |
proxy_pass http://apache/; | |
proxy_cache php; | |
proxy_cache_valid 200 30m; | |
expires 5m; | |
} | |
location ~* ^/evan/wp-admin/.+ { | |
proxy_redirect off; | |
} | |
location ~* \.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|ico)$ { | |
# Cache static-looking files for 120 minutes, setting a 10 day expiry time in the HTTP header, | |
# whether logged in or not (may be too heavy-handed). | |
proxy_cache_valid 200 120m; | |
expires 864000; | |
proxy_pass http://apache; | |
proxy_cache staticfilecache; | |
} | |
location = /50x.html { | |
root /var/www/nginx-default; | |
} | |
# No access to .htaccess files. | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment