Created
October 7, 2014 11:20
-
-
Save DmitriyLyalyuev/751e305628bb16d3e48f to your computer and use it in GitHub Desktop.
Nginx config WP Super Cache
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 default; | |
server_name example.com www.example.com; | |
server_name_in_redirect off; | |
default_type text/html; | |
set $cache_uri $request_uri; | |
# POST requests and urls with a query string should always go to PHP | |
if ($request_method = POST) { | |
set $cache_uri 'null cache'; | |
} | |
if ($query_string != "") { | |
set $cache_uri 'null cache'; | |
} | |
# Don't cache uris containing the following segments | |
if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { | |
set $cache_uri 'null cache'; | |
} | |
# Don't use the cache for logged in users or recent commenters | |
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") { | |
set $cache_uri 'null cache'; | |
} | |
location = /favicon.ico { log_not_found off; access_log off; } | |
location = /robots.txt { log_not_found off; access_log off; } | |
location / { | |
root /var/www/example.com; | |
index index.html index.htm index.php; | |
try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ @apache ; | |
access_log off; | |
location ~ .php$ { | |
proxy_pass http://127.0.0.1:8080; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|mp3)$ { | |
try_files /maintenance.html $uri/ $uri @apache; | |
access_log off; | |
expires 30d; | |
} | |
proxy_pass http://127.0.0.1:8080; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
error_page 404 502 504 = @apache; | |
} | |
location @apache { | |
proxy_pass http://127.0.0.1:8080; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment