{"id":345,"date":"2012-12-31T22:06:01","date_gmt":"2012-12-31T14:06:01","guid":{"rendered":"http:\/\/blog.yaojun.sg\/?p=345"},"modified":"2012-12-31T22:06:01","modified_gmt":"2012-12-31T14:06:01","slug":"using-regular-expressions-to-reduce-exposure","status":"publish","type":"post","link":"https:\/\/blog.yaojun.sg\/?p=345","title":{"rendered":"Using Regular Expressions to Reduce Exposure"},"content":{"rendered":"<p>The Internet is filled with bots (zombie machines working to the master&#8217;s bid), spiders and etc. Recently, I saw a large number of attempts gaining access to my WordPress Login page (and only the wp-login.php, obviously attempts from some scripts). Okay, I believe I have good password and username hygiene which did deterred the bots but then why not prevent non-public addresses from accessing it?<\/p>\n<p>Such configuration I believe can be easily done by .htaccess in Apache, but I&#8217;m using nginx and it&#8217;s slightly different so here&#8217;s my method. nginx allows the user to put rules into config so look into the your nginx configuration.<\/p>\n<p>One way to do this is to do a regular expression matching for the remote IP address ($remote_addr) or if you are like me who puts the Web Server behind a HAProxy, look at the IP address forwarded for ($http_x_forwarded_for). You can generate your IP range using <a href=\"http:\/\/support.google.com\/analytics\/bin\/answer.py?hl=en&amp;answer=1034771\">Google IP Address Range Rules (IP regular expression generator)<\/a>. And here is my additional configuration, this is to be inserted below the basic web root config.<\/p>\n<pre>location ~ \/wp-login.php {\n if ($remote_addr !~ ^(192.168.([0-7]).([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5])))$ ) { \n  \/\/Only allow my private addresses to have access\n  return 403;\n } \n\n if ($http_x_forwarded_for != \"\" ) { \n  \/\/Any proxy-ed access will be denied too\n  return 403;\n }\n\n root html;\n fastcgi_pass unix:\/tmp\/php-fpm.sock;\n fastcgi_index index.php;\n fastcgi_param SCRIPT_FILENAME \/var\/www\/html\/wordpress$fastcgi_script_name;\n include fastcgi_params;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Internet is filled with bots (zombie machines working to the master&#8217;s bid), spiders and etc. Recently, I saw a large number of attempts gaining access to my WordPress Login page (and only the wp-login.php, obviously attempts from some scripts). Okay, I believe I have good password and username hygiene which did deterred the bots [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2],"tags":[16,19,22],"class_list":["post-345","post","type-post","status-publish","format-standard","hentry","category-security","category-tech","tag-nginx","tag-php","tag-security"],"_links":{"self":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/345","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=345"}],"version-history":[{"count":0,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=\/wp\/v2\/posts\/345\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.yaojun.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}