O
O
Oleg Voitenko2019-10-25 10:42:07
Nginx
Oleg Voitenko, 2019-10-25 10:42:07

Why doesn't the NGINX setup work?

I'm trying to make a stub for the admin sites on the server through the NGINX setup

location ~* /(wp-login\.php|administrator|admin\.php) {
    set $humantest 0;
    if ($http_cookie !~* "humans=checktest") {
        set $humantest 1;
    }
    if ($args ~* (callback|logout|lostpassword)) {
        set $humantest 0;
    }
    if ($humantest = 1) {
        add_header Content-Type text/html;
        return 200 "<html><body><script>document.cookie='humans=checktest;path=/';location.reload();</script></body></html>";
    }
    error_page 404 = @fallback;
}

But it doesn't work, what's wrong with this code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2019-10-25
@OliverV

location ~ /(wp-login|admin)\.php {
    set $humantest 0;
    if ($http_cookie !~* "humans=checktest") {
        set $humantest 1;
    }
    if ($args ~* (callback|logout|lostpassword)) {
        set $humantest 0;
    }
    if ($humantest = 1) {
        add_header Content-Type text/html;
        return 200 "<html><body><script>document.cookie='humans=checktest;path=/';location.reload();</script></body></html>";
    }
    error_page 404 = @fallback;
    
    include fastcgi_params;
    fastcgi_pass ...
}

Keep in mind that location blocks given by regular expressions are checked in the order they appear in the configuration file. Regular expression checking stops after the first match. So this block must be higher thanlocation ~ \.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question