# Nginx and Wordpress Super Cache

**URL:** <https://www.ruby-forum.com/t/nginx-and-wordpress-super-cache/218754>\
**Category:** NGINX\
**Created:** [April 11, 2012, 3:36am UTC](https://www.ruby-forum.com/t/nginx-and-wordpress-super-cache/218754 "2012-04-11T03:36:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 11, 2012, 3:36am UTC](https://www.ruby-forum.com/t/nginx-and-wordpress-super-cache/218754/1 "2012-04-11T03:36:48Z")

</div>

'm trying to setup a new server with nginx instead of LAMP using  
php-fpm. I’ve got wordpress setup and running, but I’m at a loss to  
figure out how to get Wordpress Super Cache working. I’d appreciate any  
help. I’m also trying to figure out how to get rid of the if statements  
in the wordpress Multisite configuration file. I do know about the  
ifisevil page.

I’d taken my initial configuration from:  
[http://codex.wordpress.org/Nginx](http://codex.wordpress.org/Nginx)

## My Sites-available file

# Redirect everything to the main site.

server {  
listen 80 default;  
server\_name \*.students.scisdragons.net;  
rewrite ^ http://students.scisdragons.net$request\_uri permanent;  
}

server {  
server\_name [students.scisdragons.net](http://students.scisdragons.net);  
root /var/www/students.scisdragons.net;

include global/restrictions.conf;  
include global/wordpress-ms-subdir.conf;  
}

* * *

## My global wordpress file

# WordPress multisite subdirectory rules.

# Designed to be included in any server {} block.

# This order might seem weird - this is attempted to match last if rules

below fail.

# [http://wiki.nginx.org/HttpCoreModule](http://wiki.nginx.org/HttpCoreModule)

location / {  
try\_files $uri $uri/ /index.php?$args;  
}

# Add trailing slash to \*/wp-admin requests.

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

# Directives to send expires headers and turn off 404 error logging.

location ~\* .(js|css|png|jpg|jpeg|gif|ico)$ {  
expires 48h;  
log\_not\_found off;  
}

# Pass uploaded files to wp-includes/ms-files.php.

rewrite /files/$ /index.php last;

# For multisite: Use a caching plugin/script that creates symlinks to

the correct subdirectory structure to get some performance gains.  
set $cachetest  
“$document\_root/wp-content/cache/ms-filemap/${host}${uri}”;  
if ($uri ~ /$) {  
set $cachetest “”;  
}  
if (-f $cachetest) {

# Rewrites the URI and stops rewrite processing so it doesn’t start over

and attempt to pass it to the next rule.  
rewrite ^ /wp-content/cache/ms-filemap/${host}${uri} break;  
}

if ($uri !~ wp-content/plugins) {  
rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;  
}

# Uncomment one of the lines below for the appropriate caching plugin

(if used).

# include global/wordpress-ms-subdir-wp-super-cache.conf;

# include global/wordpress-ms-subdir-w3-total-cache.conf;

# Rewrite multisite ‘…/wp-._’ and '…/_.php’.

if (!-e $request\_filename) {  
rewrite ^/[\_0-9a-zA-Z-]+(/wp-._) $1 last;  
rewrite ^/[\_0-9a-zA-Z-]+(/._.php)$ $1 last;  
}

# Pass all .php files onto a php-fpm/php-fcgi server.

location ~ .php$ {

# Zero-day exploit defense.

# [nginx 0day exploit for nginx + fastcgi PHP](http://forum.nginx.org/read.php?2,88845,page=3)

# Won’t work properly (404 error) if the file is not stored on this

server, which is entirely possible with php-fpm/php-fcgi.

# Comment the ‘try\_files’ line out if you set up php-fpm/php-fcgi on

another machine. And then cross your fingers that you won’t get hacked.  
try\_files $uri =404;

fastcgi\_split\_path\_info ^(.+.php)(/.+)$;  
include fastcgi\_params;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;

# fastcgi\_intercept\_errors on;

fastcgi\_pass php;  
}

Posted at Nginx Forum:

> **[Nginx and Wordpress Super Cache](https://forum.nginx.org/read.php?2,225151,225151#msg-225151)**
>
> 'm trying to setup a new server with nginx instead of LAMP using php-fpm. I've got wordpress setup and running, but I'm at a loss to figure out how to get Wordpress Super Cache working. I'd appreciate any help. I'm also trying to figure out how to...
