Created
January 17, 2011 20:38
-
-
Save pdeschen/783442 to your computer and use it in GitHub Desktop.
nginx config for wordpress proxying
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
upstream wordpress { | |
server 127.0.0.1:80 weight=1 fail_timeout=120s; | |
} | |
server { | |
listen 81; | |
server_name blog.foo.bar; | |
proxy_cache_valid 200 20m; | |
access_log /var/log/httpd/nginx-access.log combined; | |
# for debuging, log cache hit or miss. comment out once in prod. | |
log_format up_head '[$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_x_forwarded_for" "$upstream_cache_status"'; | |
access_log /var/log/nginx/blog.foo.bar-access.log up_head; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
#unless specified, activate the caching | |
set $do_not_cache 0; | |
location / { | |
# If logged in, don't cache. | |
if ($http_cookie ~* "comment_author_ | | |
wordpress_(?!test_cookie) | | |
wp-postpass_" ) { | |
set $do_not_cache 1; | |
} | |
proxy_cache_key "$scheme://$host$request_uri $do_not_cache"; | |
proxy_cache staticfilecache; | |
proxy_pass http://wordpress; | |
} | |
location ~* wp\-.*\.php|wp\-admin { | |
proxy_pass http://wordpress; | |
} | |
location ~* \.(jpg|png|gif|jpeg|css|js|mp3|swf|pdf)$ { | |
proxy_cache_valid 200 120m; | |
expires 864000; | |
proxy_pass http://wordpress; | |
proxy_cache staticfilecache; | |
} | |
location ~* \/[^\/]+\/(feed|\.xml)\/? { | |
# Cache RSS looking feeds for 45 minutes unless logged in. | |
if ($http_cookie ~* "comment_author_| | |
wordpress_(?!test_cookie)| | |
wp-postpass_" ) { | |
set $do_not_cache 1; | |
} | |
proxy_cache_key "$scheme://$host$request_uri $do_not_cache"; | |
proxy_cache_valid 200 45m; | |
proxy_cache staticfilecache; | |
proxy_pass http://wordpress; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment