Nginx Configuration Examples

Wordpress w/ WP Supercache (Full-On mode)


server {
	listen 80;

	server_name example.com www.example.com;

	root /usr/local/www/example.com;

	access_log /var/log/nginx/example.access.log;
	error_log /var/log/nginx/example.error.log;

	location / { 
		# This line when enabled will use Nginx's gzip static module
		gzip_static on;
 
		# Disables serving gzip content to IE 6 or below
		gzip_disable "MSIE [1-6]\.";
 
		# Sets the default type to text/html so that gzipped content is served
		# as html, instead of raw uninterpreted data.
		default_type text/html;
 
		# does the requested file exist exactly as it is? if yes, serve it and stop here
		if (-f $request_filename) { break; }
 
		# sets some variables to help test for the existence of a cached copy of the request
		set $supercache_file '';
		set $supercache_uri $request_uri;
 
		# IF the request is a post, has a query attached, or a cookie
		# then don't serve the cache (ie: users logged in, or posting comments)
		if ($request_method = POST) { set $supercache_uri ''; }
		if ($query_string) { set $supercache_uri ''; }
		if ($http_cookie ~* "comment_author_|wordpress|wp-postpass_" ) { 
			set $supercache_uri ''; 
		}
 
		# if the supercache_uri variable hasn't been blanked by this point, attempt
		# to set the name of the destination to the possible cache file
		if ($supercache_uri ~ ^(.+)$) { 
			set $supercache_file /wp-content/cache/supercache/$http_host/$1index.html; 
		}
 
		# If a cache file of that name exists, serve it directly
		if (-f $document_root$supercache_file) { rewrite ^ $supercache_file break; }
 
		# Otherwise send the request back to index.php for further processing
		if (!-e $request_filename) { rewrite ^ /index.php last; }
	}
	
	location /search { limit_req zone=kbeezieone burst=3 nodelay; rewrite ^ /index.php; }

	fastcgi_intercept_errors off;
	
	location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
		expires max;
		add_header Pragma public;
		add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	}
	
	include php.conf;

	# You may want to remove the robots line from drop to use a virtual robots.txt
	# or create a drop_wp.conf tailored to the needs of the wordpress configuration
	include drop.conf;
}

Nibbleblog 3.4.1+ with Pretty URLs enabled

If you're using NibbleBlog ( http://nibbleblog.com ), the following basic configuration works with version 3.4.1, and 3.4.1 Markdown.


server {
 listen 80;
 root /usr/local/www/example.com;;
 server_name example.com www.example.com;
 
 # access log turned off for speed
 access_log off;
 error_log /var/log/nginx/domain.error.log;
 
 # main location block
 location / {
 expires 7d;
 try_files $uri $uri/ @rewrites;
 }

 # rewrite rules if file/folder did not exist
 location @rewrites {
 rewrite ^/dashboard$ /admin.php?controller=user&action=login last;
 rewrite ^/feed /feed.php last;
 rewrite ^/category/([^/]+)/page-([0-9]+)$ /index.php?controller=blog&action=view&category=$1&page=$2 last;
 rewrite ^/category/([^/]+)/$ /index.php?controller=blog&action=view&category=$1&page=0 last;
 rewrite ^/page-([0-9]+)$ /index.php?controller=blog&action=view&page=$1 last;
 }
 
 # location catch for /post-#/Post_Title
 # will also catch odd instances of /post-#/something.php
 location ~ ^/post-([0-9]+)/ {
 rewrite ^ /index.php?controller=post&action=view&id_post=$1 last;
 }
 
 # cache control for static files
 location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
 expires max;
 add_header Pragma public;
 add_header Cache-Control "public, must-revalidate, proxy-revalidate";
 }

	include drop.conf;
	include php.conf;
}