Created
June 1, 2016 17:07
-
-
Save juliosmelo/76ed7c6fdeedcfef7621d58f01d370f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 backend{ | |
# Defines backends. | |
# Extracting here makes it easier to load balance | |
# in the future. Needs to be specific IP as Plesk | |
# doesn't have Apache listening on localhost. | |
ip_hash; | |
server 127.0.0.1:8080; # IP goes here. | |
} | |
server { | |
listen 80 default_server; # IP goes here. | |
server_name _; | |
# Max upload size: make sure this matches the php.ini in .htaccess | |
client_max_body_size 20m; | |
access_log /var/log/nginx/cache_access.log rt_cache; | |
# Catch the wordpress cookies. | |
# Must be set to blank first for when they don't exist. | |
set $user_auth ""; | |
if ($http_cookie ~* "wordpress_logged_in_[^=]*=([^%]+)%7C") { | |
set $user_auth user_auth_$1; | |
} | |
if ($http_cookie ~* "ci_session_app") { | |
set $user_auth user_auth_$1; | |
} | |
# Set the proxy cache key | |
set $cache_key $scheme$host$uri$is_args$args; | |
# Don't cache these pages. | |
location ~* ^/(wp-admin|wp-login.php){ | |
more_clear_headers "X-Powered-By"; | |
proxy_pass http://backend; | |
} | |
location ~* ^/(ec){ | |
proxy_pass http://backend; | |
more_set_headers "Server: Elav Hosting"; | |
more_clear_headers "X-Powered-By"; | |
} | |
location / { | |
proxy_pass http://backend; | |
proxy_cache main; | |
proxy_cache_key $cache_key; | |
proxy_cache_valid 5m; # 200, 301 and 302 will be cached. | |
# Fallback to stale cache on certain errors. | |
# 503 is deliberately missing, if we're down for maintenance | |
# we want the page to display. | |
proxy_cache_use_stale error | |
timeout | |
invalid_header | |
http_500 | |
http_502 | |
http_504 | |
http_404; | |
# 2 rules to dedicate the no caching rule for logged in users. | |
proxy_cache_bypass $user_auth; # Do not cache the response. | |
proxy_no_cache $user_auth; # Do not serve response from cache. | |
proxy_set_header X-Forwarded-For $remote_addr; | |
dd_header X-Cache $upstream_cache_status; | |
more_set_headers "Server:Host Cache"; | |
more_clear_headers "X-Powered-By"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment