Skip to content

Instantly share code, notes, and snippets.

@DarrylDias
Last active November 29, 2017 12:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DarrylDias/33c1582f97656649825f to your computer and use it in GitHub Desktop.
Save DarrylDias/33c1582f97656649825f to your computer and use it in GitHub Desktop.
WordPress optimised NGINX config for http://darryldias.me/lightweight-wordpress-setup/
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WP:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;
server {
listen 80;
root /var/www/wp; # Change the web root with the place where your WordPress is setup
index index.php ;
server_name yourawesome.com; # Change the domain with your domain
set $no_cache 0; # 0 is false
# Prevent nginx from caching login and admin panel
if ($request_uri ~* "/(wp-admin/|wp-login.php)")
{
set $no_cache 1; # 1 is true
}
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock; # Change the socket if you are using different FastCGI setup
fastcgi_index index.php;
include fastcgi_params;
fastcgi_cache WP;
fastcgi_cache_valid 200 60m; # Will cache valid 200 request for 60 Minutes, Increase this time to your preference
fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
fastcgi_hide_header "Set-Cookie"; # Cache page with cookie
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment