Cant get into wp-admin page (cloudflare, nginx)

xPalis asked:

I have a wordpress website that is running on Nginx behind cloudflare DNS. I have used “set_real_ip_from” for all cloudflare ips in nginx.conf. When i try to access my website i can see my real ip in the logs. I have changed the default wordpress admin login directory from wp-admin to my directory name. I only want specific ips to be allowed to login to my wordpress but with this in my websites config, server block: location ~ /(wp-admin|wp-login|mydirectory) {
allow my.real.ip;
deny all;
return 404;
}
i cant seem to access wordpress admin and i get 404. If i delete this block everything is working fine so i guess im typing something wrong ? i looked around on this forum with some different variations but none of them seem to work. They either allow me to access to wp-admin but then anyone can access or it blocks everyone.

My answer:


You get a 404 because you specifically asked for a 404 for all requests matching that location.

    return 404;

You will need to remove this statement if you want to receive anything other than a 404.

Further, you will need to place a nested location within that location to process PHP files.

location ~ /(wp-admin|wp-login|mydirectory) {
    ...
    location ~ .php$ {
        ....

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.