Skip to content

Instantly share code, notes, and snippets.

@gemmadlou
Last active April 12, 2018 20:18
Show Gist options
  • Select an option

  • Save gemmadlou/eebeeb4bcbdc1892fb37d36d0fec2924 to your computer and use it in GitHub Desktop.

Select an option

Save gemmadlou/eebeeb4bcbdc1892fb37d36d0fec2924 to your computer and use it in GitHub Desktop.
nginx Example config for wp

I can't take credit. Adam Lewis - awesome dev created one and I've taken what he's done.

server {
listen 80;
server_name somesite.com;
root /var/www/vhosts/somewebsite/public;
# pass the PHP scripts to FastCGI server
#
# See conf.d/php-fpm.conf for socket configuration
#
index index.php index.html index.htm;
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-fpm;
}
# WordPressy stuff
# 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;
}
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
# Caching
location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|woff2|svg)$ {
expires max;
log_not_found off;
}
# Global restrictions configuration file.
# Designed to be included in any server {} block.
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;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment