Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ngnix Configaration
server {
# This redirects the non-www version of the domain name to the www version
server_name domain.com;
rewrite ^ $scheme://www.domain.com$request_uri? permanent;
}
server {
server_name www.domain.com;
root /var/www/domain/httpdocs;
index index.html index.htm index.php;
access_log /var/www/domain/logs/access.log;
error_log /var/www/domain/logs/error.log;
location ~ \.php$ {
# The next two lines address a security flaw in NGINX.
# https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/domain/httpdocs$fastcgi_script_name;
}
# Disable index.php and make WordPress permalinks work
location / {
try_files $uri $uri/ /index.php?$args;
}
# Expires header to improve SEO (Google Page Speed)
location ~* \.(ico|css|js|gif|jpg|jpeg|png|xml|pdf)$ {
expires 1w;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
log_not_found off;
}
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
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Don't log and deny access to files which end with ~, as these are usually backup files.
location ~ ~$ {
access_log off;
log_not_found off;
deny all;
}
}
@AbhishekGhosh

This comment has been minimized.

Copy link
Owner Author

AbhishekGhosh commented Mar 27, 2014

This is gist is created by Abhishek Ghosh for the blog article Installing WordPress With NGINX on Debian.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.