Skip to content

Instantly share code, notes, and snippets.

/nginx_conf Secret

Created February 3, 2017 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/2a9e2a44c28560a5647ee1ad515051d2 to your computer and use it in GitHub Desktop.
Save anonymous/2a9e2a44c28560a5647ee1ad515051d2 to your computer and use it in GitHub Desktop.
I setup a WordPress service which it's use Plesk : ' Nginx proxy cache -> apache -> WordPress -> Redis -> MySQL ' Everything looks good but when I'm trying to install a plugin or theme on WordPress I'm getting Nginx timeout error, I don't have an idea why Nginx give that error because I'd thought it would only handle incoming requests. If you ha…
set $bypass_cache 0;
add_header X-CACHE $upstream_cache_status;
# Don't cache POST Request
if ($request_method = POST) {
set $bypass_cache 1;
}
# WooCommerce support
if ( $cookie_woocommerce_items_in_cart = "1" ){
set $bypass_cache 1;
}
if ($request_uri ~* "/(cart|checkout|my-account|sepet|odeme|hesabim)/*$") {
set $bypass_cache 1;
}
if ($query_string != "") {
set $bypass_cache 1;
}
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wordpress_logged_in|code") {
set $bypass_cache 1;
}
# This prevents hidden files (beginning with a period) from being served
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}
# Don't use cache app cache and cache manifest
location ~* \.(?:manifest|appcache)$ {
expires -1;
}
# Don't cache url's containing the following segments
if ($request_uri ~* "/wp-admin/|/admin-*|/purge*|/xmlrpc.php|wp-.*.php|/feed/|sitemap(_index)?.xml") {
set $bypass_cache 1;
}
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 $bypass_cache 1;
}
# Purge the given page
location ~ /purge(/.*) {
proxy_cache_purge STATIC $host$1$is_args$args;
}
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|min|min.js|min.css)$ {
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wordpress_logged_in|code") {
expires -1;
}
proxy_read_timeout 6;
proxy_connect_timeout 3;
proxy_redirect off;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ignore_headers Expires Set-Cookie Cache-Control;
proxy_pass http://HOST_IP:PORT;
proxy_cache_valid 200 301 302 304 180m;
proxy_cache_valid 404 1m;
proxy_cache STATIC;
proxy_cache_revalidate on;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
proxy_cache_use_stale updating;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
expires 180m;
add_header Cache-Control "public, no-transform";
}
location ~ ^/ {
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wordpress_logged_in|code") {
expires -1;
}
proxy_cache_bypass $bypass_cache;
proxy_no_cache $bypass_cache;
proxy_pass http://HOST_IP:PORT;
proxy_read_timeout 6;
proxy_connect_timeout 3;
proxy_redirect off;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ignore_headers Expires Set-Cookie Cache-Control;
proxy_cache_methods GET HEAD;
proxy_cache_valid 200 301 302 304 60m;
proxy_cache_valid 404 1m;
proxy_cache STATIC;
proxy_cache_revalidate on;
proxy_cache_lock on;
proxy_cache_lock_timeout 5s;
proxy_cache_use_stale updating;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment