To protect the WordPress admin dashboard (/wp-admin/) and login page (wp-login.php), we primarily recommend enabling two-factor authentication (2FA) and using strong passwords. However, if your site administrators connect from static IP addresses (such as an office network or a dedicated VPN), you can also restrict access to login endpoints at the server level using nginx rules.
Step 1: Create Allowed IP Address Lists
To ensure Seravo's automated site monitoring and internal cluster maintenance continue working without interruption, you must allow access from Seravo's monitoring and cluster IP addresses as well.
Seravo Monitoring and Cluster IP Addresses
Create the file /data/wordpress/nginx/seravo-monitoring.rules and add localhost alongside Seravo's monitoring server IP addresses:
# Local connections
allow 127.0.0.1;
allow ::1;
# Seravo monitoring
allow 94.237.85.150;
allow 2a04:3542:1000:910:7c25:3fff:fe79:23da;
Check your site cluster's IPv4 and IPv6 addresses via SSH using the following command:
srv system metadata
Create the file /data/wordpress/nginx/seravo-cluster-ip-list.rules and add the cluster IP addresses returned by the command:
allow <cluster-ipv4-address>;
allow <cluster-ipv6-address>;
Your Allowed IP Addresses
Create the file /data/wordpress/nginx/allowed-ip-list.rules and add all IPv4 and IPv6 addresses permitted to access the admin dashboard:
allow 198.51.100.10;
allow 2001:db8::1;
Step 2: Enable IP Restrictions in nginx
Create the main configuration file /data/wordpress/nginx/wp-admin-restrict.conf. Use Seravo's built-in system snippet /etc/nginx/snippets.d/php.conf to handle PHP-FPM routing.
Note that /wp-admin/admin-ajax.php must remain accessible to all visitors so that public-facing theme and plugin AJAX requests continue working properly:
# Allow admin-ajax.php for all visitors (required for frontend functionality)
location = /wp-admin/admin-ajax.php {
allow all;
try_files $uri =404;
include /etc/nginx/snippets.d/php.conf;
}
# Restrict access to the login page
location = /wp-login.php {
include /data/wordpress/nginx/seravo-monitoring.rules;
include /data/wordpress/nginx/seravo-cluster-ip-list.rules;
include /data/wordpress/nginx/allowed-ip-list.rules;
deny all;
limit_req zone=loginflood nodelay burst=3;
try_files $uri =404;
include /etc/nginx/snippets.d/php.conf;
}
# Restrict access to admin dashboard PHP files
location ~ ^/wp-admin/.*\.php$ {
include /data/wordpress/nginx/seravo-monitoring.rules;
include /data/wordpress/nginx/seravo-cluster-ip-list.rules;
include /data/wordpress/nginx/allowed-ip-list.rules;
deny all;
try_files $uri =404;
include /etc/nginx/snippets.d/php.conf;
}
# Restrict access to other files under /wp-admin/
location ~ ^/wp-admin/ {
include /data/wordpress/nginx/seravo-monitoring.rules;
include /data/wordpress/nginx/seravo-cluster-ip-list.rules;
include /data/wordpress/nginx/allowed-ip-list.rules;
deny all;
}
Apply the changes by restarting nginx:
wp-restart-nginx
Warning: Never apply IP restrictions across the entire site (location /), as doing so blocks regular visitors as well as Seravo's automated monitoring and maintenance operations.
Alternative Method: Restrict Login Page Access by Country (GeoIP)
If you cannot rely on static IP addresses, but your administrators only log in from specific countries, you can restrict access to wp-login.php using Seravo's X-Seravo-Geo-Country-Code header.
Create the file /data/wordpress/nginx/wp-login-geo.conf:
location = /wp-login.php {
# Allow logins only from Finland, Sweden, and Estonia
if ($http_x_seravo_geo_country_code !~* "^(FI|SE|EE)$") {
return 403;
}
limit_req zone=loginflood nodelay burst=3;
try_files $uri =404;
include /etc/nginx/snippets.d/php.conf;
}
Apply the configuration with wp-restart-nginx.
Note: Country-based restrictions can lock out legitimate administrators while traveling abroad or using a VPN, and they do not protect against attacks originating from within allowed countries. We primarily recommend enabling two-factor authentication (2FA).
Common Issues and Troubleshooting
You locked yourself out of the dashboard after your IP address changed: Internet service providers regularly rotate IPv4 and IPv6 addresses on home and mobile connections. Connect to the server via SSH, update your new IP address in
/data/wordpress/nginx/allowed-ip-list.rules, and runwp-restart-nginx.Forms, shopping carts, or other site features stopped working after adding restrictions: Verify that the
location = /wp-admin/admin-ajax.phpexception is defined in/data/wordpress/nginx/wp-admin-restrict.confbefore the broader/wp-admin/rules.The site returns
403 Forbiddendespite connecting from an allowed IP address: Your connection may be routing over IPv6 even though you only whitelisted an IPv4 address (or vice versa). Check/data/log/nginx-access.logto see which IP address reached the server, and add both addresses to your allowlist.Changes do not take effect or
wp-restart-nginxreports an error: Double-check the spelling of allincludefile paths and ensure every rule ends with a semicolon (;), then runwp-restart-nginxagain.
See Also
Restricting access to the admin dashboard and login page effectively reduces server load caused by automated brute-force login attempts. If you need assistance configuring nginx rules or identifying the appropriate IP addresses, our support team is happy to help at [email protected].
