Last active
August 29, 2015 14:02
-
-
Save damonp/c501e031a90ff062b2c9 to your computer and use it in GitHub Desktop.
Nginx Conf For Wordpress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://codex.wordpress.org/Nginx | |
# nginx.conf | |
# Generic startup file. | |
user {user} {group}; | |
#ususally equal to number of CPU's you have. run command "grep processor /proc/cpuinfo | wc -l" to find it | |
worker_processes 2; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
# Keeps the logs free of messages about not being able to bind(). | |
#daemon off; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
# rewrite_log on; | |
include mime.types; | |
default_type application/octet-stream; | |
access_log /var/log/nginx/access.log; | |
sendfile on; | |
# tcp_nopush on; | |
keepalive_timeout 3; | |
# tcp_nodelay on; | |
# gzip on; | |
#php max upload limit cannot be larger than this | |
client_max_body_size 13m; | |
index index.php index.html index.htm; | |
# Upstream to abstract backend connection(s) for PHP. | |
upstream php { | |
#this should match value of "listen" directive in php-fpm pool | |
server unix:/tmp/php-fpm.sock; | |
# server 127.0.0.1:9000; | |
} | |
include sites-enabled/*; | |
} | |
# domain.conf | |
# Redirect everything to the main site. We use a separate server statement and NOT an if statement - see http://wiki.nginx.org/IfIsEvil | |
server { | |
server_name _; | |
rewrite ^ $scheme://mysite.com$request_uri redirect; | |
} | |
server { | |
server_name mysite.com; | |
root /var/www/mysite.com; | |
include global/restrictions.conf; | |
# Additional rules go here. | |
# Only include one of the files below. | |
include global/wordpress.conf; | |
} | |
# global/wordpress.conf | |
# WordPress single blog 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 | |
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 ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|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 max; | |
} | |
# Uncomment one of the lines below for the appropriate caching plugin (if used). | |
#include global/wordpress-wp-super-cache.conf; | |
#include global/wordpress-w3-total-cache.conf; | |
# Pass all .php files onto a php-fpm/php-fcgi server. | |
location ~ \.php$ { | |
# Zero-day exploit defense. | |
# 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)(/.+)$; | |
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini | |
include fastcgi_params; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
# fastcgi_intercept_errors on; | |
fastcgi_pass php; | |
} | |
# global/restrictions.conf | |
# Global restrictions configuration file. | |
# Designed to be included in any server {} block.</p> | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). | |
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) | |
location ~ /\. { | |
deny all; | |
} | |
# Deny access to any files with a .php extension in the uploads directory | |
# Works in sub-directory installs and also in multisite network | |
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban) | |
location ~* /(?:uploads|files)/.*\.php$ { | |
deny all; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment