server {
listen 8080;
server_name example.com *.example.com;
root /srv/www/example.com/public;
access_log /srv/www/example.com/log/access.log;
error_log /srv/www/example.com/log/error.log;
include wordpress.conf;
include browsercache.conf;
include drop.conf;
include php.conf;
}
wordpress.conf:
location / {
index index.php;
if (-f $request_filename) {
break;
}
set $pgcache "";
if ($request_method = GET) { set $pgcache "${pgcache}D"; }
if ($args = "") { set $pgcache "${pgcache}I"; }
if ($http_cookie !~ (comment_author_|wordpress|wordpress_logged_in|wp-postpass_)) {
set $pgcache "${pgcache}S";
}
if (-f $document_root/wp-content/w3tc/pgcache/$request_uri/_index.html) {
set $pgcache "${pgcache}K";
}
if ($pgcache = "DISK") {
rewrite ^ /wp-content/w3tc/pgcache/$request_uri/_index.html break;
}
if (!-e $request_filename) { rewrite ^ /index.php last; }
}
location /search {
limit_req zone=wpsearch burst=3 nodelay;
try_files $uri /index.php;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Prohibit php files from executing in wp-uploads
location ~* ^/wp-content/uploads/.*.php$ {
return 403;
}
# enforce www (exclude certain subdomains)
if ($host !~* ^(www|subdomain))
{
rewrite ^/(.*)$ $scheme://www.$host/$1 permanent;
}
fastcgi_intercept_errors off;
browsercache.conf:
# browser cache
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
drop.conf:
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
php.conf:
location ~ \.php {
client_max_body_size 25M;
try_files $uri =404;
limit_conn phplimit 5;
fastcgi_index index.php;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param HTTPS $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}