Last active
November 29, 2017 12:24
-
-
Save DarrylDias/33c1582f97656649825f to your computer and use it in GitHub Desktop.
WordPress optimised NGINX config for http://darryldias.me/lightweight-wordpress-setup/
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
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