KBeezie

There's no place like ::1

Menu
  • Home
  • Start Here
  • Security Series
  • About

Nginx Configuration Examples

2011/03/31 in Archived

Drupal 6+
From http://wiki.nginx.org/Drupal with some changes


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;
	
	# This matters if you use drush
	location = /backup {
		deny all;
	}
 
	# Very rarely should these ever be accessed outside of your lan
	location ~* \.(txt|log)$ {
		allow 192.168.0.0/16;
		deny all;
	}
 
	location ~ \..*/.*\.php$ { return 403; }
 
	location / {
		# This is cool because no php is touched for static content
		try_files $uri @rewrite;
	}
 
	location @rewrite {
		# Some modules enforce no slash (/) at the end of the URL
		# Else this rewrite block wouldn't be needed (GlobalRedirect)
		rewrite ^/(.*)$ /index.php?q=$1;
	}
 
	# Fighting with ImageCache? This little gem is amazing.
	location ~ ^/sites/.*/files/imagecache/ {
		try_files $uri @rewrite;
	}
	
	location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
		expires max;
		add_header Pragma public;
		add_header Cache-Control "public, must-revalidate, proxy-revalidate";
		log_not_found off;
	}

	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;
}

Static with an Apache (for dynamic) Backend


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 / { 
		# Rewrite rules can go here
	}
	
	location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
		expires max;
		add_header Pragma public;
		add_header Cache-Control "public, must-revalidate, proxy-revalidate";
	}
	
	location ~ \.php {
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $remote_addr;

		proxy_set_header Host $host;
 
		proxy_pass http://127.0.0.1:8080;
	}
	
	include drop.conf;
}
  • ← Previous
  • 1
  • 2
  • 3
  • 4
  • Next →
Tags: archived, nginx, wordpress, drupal
©2026 Karl Blessing | Disclaimer | Privacy Notice