3

i'm trying to acheive something in nginx but i'm having a hard time. Basically i want to ask for a password everytime my api receive any HTTP methods except POST and PUT , it works to some extent because the password prompts appear when trying to send a GET , but the rewrite command is not executed and nginx doesn't pass the correct route to the API that returns a 404 ( works fine if i dont try to use limit_except).

If anyone achieved anything similar it will help me a lot!

Thanks !

     location /apis/app/{
                rewrite /apis/app/(.*) /$1 break;
                limit_except POST PUT {
                auth_basic "Restricted";
                auth_basic_user_file  /var/www/html/apps/app/.htpasswd;
                }
                proxy_pass                      http://my_adress;
                proxy_redirect          off;
                proxy_set_header        Host                            $http_host;
                proxy_set_header        X-Real-IP                       $remote_addr;
                proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto       $scheme;
                add_header      tokentooap      app;
                limit_req zone=one;
        }
        location /apps/app/{
                try_files $uri $uri/ /apps/app/index.html;}
  • I faced exactly the same problem and seemingly nobody raised the problem so far. Would happy to know how did you solve it in the end. – Shi B. Feb 08 '21 at 17:14
  • Just came across the very same problem. The rewrite doesn't work when limit_except is in the same location. Have not found the reason yet why. – Claudio Kuenzler Feb 18 '22 at 13:37
  • 1
    It might either be a bug in Nginx or an unclear documentation, see https://trac.nginx.org/nginx/ticket/2323 If it's "just" a missing information in the documentation, that would mean you'd have to set the rewrite once again inside the limit_except context. – Claudio Kuenzler Feb 18 '22 at 15:02

0 Answers0