Created
June 13, 2016 14:41
-
-
Save khoatran/5e6288c1b1b76065093c623e25e4658b to your computer and use it in GitHub Desktop.
Nginx configuration for Wordpress - with fast cgi 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; | |
server_name website-domain.com; | |
root /data/apps/excitingthing; | |
index index.html index.htm index.php; | |
charset utf-8; | |
set $skip_cache 0; | |
# POST requests and urls with a query string should always go to PHP | |
if ($request_method = POST) { | |
set $skip_cache 1; | |
} | |
if ($query_string != "") { | |
set $skip_cache 1; | |
} | |
# Don't cache uris containing the following segments | |
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { | |
set $skip_cache 1; | |
} | |
# Don't use the cache for logged in users or recent commenters | |
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { | |
set $skip_cache 1; | |
} | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
if (!-e $request_filename) { | |
rewrite /wp-admin$ $scheme://$host$uri/ permanent; | |
rewrite ^(/[^/]+)?(/wp-.*) $2 last; | |
rewrite ^(/[^/]+)?(/.*\.php) $2 last; | |
} | |
access_log off; | |
error_log /var/log/nginx/excitingthing-error.log error; | |
sendfile off; | |
client_max_body_size 100m; | |
location ~ \.php$ { | |
fastcgi_split_path_info ^(.+\.php)(/.+)$; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_intercept_errors off; | |
fastcgi_buffer_size 16k; | |
fastcgi_buffers 4 16k; | |
fastcgi_cache_bypass $skip_cache; | |
fastcgi_no_cache $skip_cache; | |
fastcgi_cache WORDPRESS; | |
fastcgi_cache_valid 60m; | |
} | |
location ~ /purge(/.*) { | |
fastcgi_cache_purge WORDPRESS "$scheme$request_method$host$1"; | |
} | |
location ~ /\.ht { | |
deny all; | |
} | |
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { | |
access_log off; log_not_found off; expires max; | |
} | |
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ { | |
expires 365d; | |
} | |
rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment