Skip to content

Instantly share code, notes, and snippets.

@AbhishekGhosh
Created March 7, 2014 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AbhishekGhosh/9407378 to your computer and use it in GitHub Desktop.
Save AbhishekGhosh/9407378 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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