Skip to content

Instantly share code, notes, and snippets.

@artistio
Created July 14, 2016 13:51
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 artistio/44046530d5d403b94309ed2ad0bbdfc6 to your computer and use it in GitHub Desktop.
Save artistio/44046530d5d403b94309ed2ad0bbdfc6 to your computer and use it in GitHub Desktop.
NGINX site specification to run Wordpress Multisite with Domain Mapping. This site use fastcgi cache to speed up PHP execution Support HTTPS is also available. To use, put this file in /etc/nginx/site-available, and symlink to /etc/nginx/site-enabled
fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=WP:32m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;
server {
listen [::]:80 ipv6only=off;
listen [::]:443 ipv6only=off ssl;
# Change the line below according to domain served by this Wordpress. Include all domain
server_name example.com *.example.com example.org *.example.org;
root /var/www/html;
index index.php index.html index.htm;
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?$args ;
}
location ~ /favicon.ico {
access_log off;
log_not_found off;
}
# Blocking php access to images & upload directory
location ~* /images/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
# Blocking php access to icon directory
location ~* /icon/.*.php$ {
deny all;
access_log off;
log_not_found off;
}
location ~ \.php$ {
try_files $uri /index.php;
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_cache WP;
fastcgi_cache_valid 200 60m;
}
# location ~ /purge(/.*) {
# fastcgi_cache_purge WP "$scheme$request_method$host$request_uri";
# }
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)$ {
access_log off;
log_not_found off;
expires 30d;
}
location = /robots.txt {
access_log off;
log_not_found off;
}
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
ssl_certificate /etc/nginx/ssl/publickey.pem;
ssl_certificate_key /etc/nginx/ssl/privatekey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
access_log /var/log/nginx/$host-access.log rt_cache;
# Used to test Cache performance of fastcgi
#access_log /var/log/nginx/$host-cache.log rt_cache;
error_log /var/log/nginx/wpms-error.log;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment