nginx-install/nginxsnippets/wphardening.conf

56 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

2024-10-13 00:56:32 +02:00
# Wordpress deny xmlrpc start #####################################################################################################
location = /xmlrpc.php {
deny all;
access_log off;
log_not_found off;
return 444;
}
# Wordpress deny xmlrpc stop ######################################################################################################
# Wordpress deny wp-cron start ####################################################################################################
location = /wp-cron.php {
deny all;
access_log off;
log_not_found off;
return 444;
}
# Wordpress deny wp-cron stop #####################################################################################################
# Wordpress limit get post start ##################################################################################################
if ($request_method !~ ^(GET|POST)$ ) {
return 444;
}
# Wordpress limit get post stop ###################################################################################################
# Wordpress deny php files where they dont belong start ###########################################################################
location ~* /(?:uploads|files|wp-content|wp-includes)/.*.php$ {
deny all;
access_log off;
log_not_found off;
return 444;
}
# Wordpress deny php files where they dont belong stop ############################################################################
# Wordpress limit request pr. sec here its 5 req/sec start ########################################################################
location = /wp-login.php {
limit_req zone=RATELIMIT burst=3 nodelay;
limit_req_status 444;
include snippets/fastcgi-php.conf;
2024-10-19 11:23:11 +02:00
fastcgi_pass unix:/var/run/php/phpVERSION-fpm.sock;
2024-10-13 00:56:32 +02:00
}
# NOTE: The above requires the following file to exist:
# /etc/nginx/conf.d/rate-limit.conf with the following content:
# limit_req_zone $binary_remote_addr zone=RATELIMIT:10m rate=10r/s;
# Wordpress limit request pr. sec here its 5 req/sec stop #########################################################################
# Wordpress deny access to the following files in upload directory start ##########################################################
location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php|js|swf)$ {
deny all;
}
# Wordpress deny access to the following files in upload directory stop ###########################################################
# Wordpress dont cache certain pages start ########################################################################################
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") { set $skip_cache 1; }
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; }
# Wordpress dont cache certain pages stop #########################################################################################