nginx is not returning 200 but going through the api server and returning 400

Viewed 51

I'm trying to return a 2xx status code from a specific path using nginx. this path should support POST only.

This is the code I have:

        location = /v1/rest/v1/example/webhook {
            return 200;
            break;
        }
            

But it kept bypassing the code above, and went straight to the api server (/v1) which I'm trying to prevent.

Here is an overview of related blocks:

    server {
        listen      443 ssl;
        listen      [::]:443 ssl ipv6only=on;
        server_name staging.example.com, api.staging.example.com;
        root        /usr/share/nginx/html;


        location = /v1/rest/v1/example/webhook {
            return 200;
            break;
        }
        
        location / {
            proxy_http_version 1.1;
            proxy_set_header Host $http_host;
            proxy_request_buffering off;
            proxy_pass http://HOST:PORT;
            server_name_in_redirect off;
        }

        location ^~ /v1 {
            rewrite /v1/(.*) /$1  break;

            limit_req zone=nginx_main burst=50 nodelay;
            limit_req_status 444;

            proxy_http_version 1.1;
            proxy_set_header Host $http_host;
            proxy_request_buffering off;
            proxy_pass http://HOST:PORT;
            server_name_in_redirect off;
            auth_basic off;
        }



        error_page 400 404 /40x.html;
        location = /40x.html {
            limit_req zone=nginx_main burst=10 nodelay;
            limit_req_status 444;
        }

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            limit_req zone=nginx_main burst=10 nodelay;
            limit_req_status 444;
        }

    }

Placing the block on top of the others did not help.

0 Answers
Related