# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac). location ~ /\. { deny all; } # Deny access to any files with a .php extension in the uploads directory location ~* /uploads/.*\.php$ { deny all; } # Deny access to any files with a .php extension in the uploads directory for multisite location ~* /files/.*\.php$ { deny all; } # Since version 2.5.7, Akismet introduced a new .htaccess file to block direct access to php files # Ref: http://wordpress.org/extend/plugins/akismet/changelog/ location ~* /akismet/.*\.php$ { allow 127.0.0.1; deny all; } # Restrict direct access to cached content location /wp-content/cache/ { deny all; } # hide any backup or SQL dump files location ~ ^.+\.(sql|bak|php~|php#|php.save|php.swp|php.swo)$ { deny all; } #Deny access to wp-content folders for suspicious files location ~* ^/(wp-content)/(.*?)\.(zip|gz|tar|bzip2|7z)\$ { deny all; } location ~ ^/wp-content/uploads/sucuri { deny all; } location ~ ^/wp-content/updraft { deny all; } #Disable execution of scripts other than PHP from your document root location ~* .(pl|cgi|py|sh|lua|asp)$ { return 444; } #Disable access to your configuration files and other files that you don’t want to users are able to see location ~* /(wp-config.php|readme.html|license.txt|nginx.conf) { deny all; } # Disable wp-config.txt location = /wp-config.txt { deny all; } # nginx block wpscann on plugins folder location ~* ^/wp-content/plugins/.+\.(txt|log|md)$ { deny all; error_page 403 =404 / ; } # 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; } # Stop scann for the follow files on plugins folder location ~* ^/wp-content/plugins/.+\.(txt|log|md)$ { deny all; error_page 403 =404 / ; } # Stop scann for the follow files on themes folder location ~* ^/wp-content/themes/.+\.(txt|log|md)$ { deny all; error_page 403 =404 / ; } #This module will allow us to pattern match certain key files and inject random text in the files that # is non-destructive / non-invasive and will most importantly alter the md5sum calculated on such files. All transparent to WPScan. location ~* ^/(license.txt|wp-includes/(.*)/.+\.(js|css)|wp-admin/(.*)/.+\.(js|css))$ { sub_filter_types text/css text/javascript text/plain; sub_filter_once on; sub_filter ';' '; /* $msec */ '; } #Direct PHP File Access #If somehow, a hacker successfully sneaks in a PHP file onto your site, #they’ll be able to run this file by loading file which effectively becomes a backdoor to infiltrate your site. #We should disable direct access to any PHP files by adding the following rules: location ~* /(?:uploads|files|wp-content|wp-includes|akismet)/.*.php$ { deny all; } #Dotfiles #Similar to PHP file, a dotfile like .htaccess, .user.ini, and .git may contain sensitive information. #To be on the safer side, it’s better to disable direct access to these files. location ~ /\.(svn|git)/* { deny all; } location ~ /\.ht { deny all; } location ~ /\.user.ini { deny all; } #WordFence location ~ \.user\.ini$ { deny all; } # WordPress: deny wp-content, wp-includes php files location ~* ^/(?:wp-content|wp-includes)/.*\.php$ { deny all; } # WordPress: deny wp-content/uploads nasty stuff location ~* ^/wp-content/uploads/.*\.(?:s?html?|php|js|swf)$ { deny all; }