0

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.

EDIT Unfortunately i couldnt get it to work no matter what i tried so what i did was deleted the location ~ /(wp-admin|wp-login|mydirectory) block, reloaded nginx config, logged in to wordpress, disabled wp-admin change directory plugin, then went back and re-added the location ~ /(wp-admin|wp-login|mydirectory) block inside it i added location ~ .php$ { as @Michael Hampton suggested and now i can access my wordpress admin page by using "wp-admin" url. Dont know why it didnt work with the custom url but i guess this will do since nginx will block anyone else trying to access it tho it would have been interesting to know why it didnt work :/

0

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$ {
        ....
  • Thank you for the answer, I am fully aware why i get 404 because as you said i set it that way. My question was why i get 404 even tho my ip is set to allow. I had to resort to something else to make this work unfortunately :/ – xPalis Dec 14 '17 at 17:06
  • Again, you get a 404 because you asked for a 404. – Michael Hampton Dec 14 '17 at 18:12
  • My bad i thought if i use return after deny thats what everyone else would get :/ – xPalis Dec 15 '17 at 19:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.