nginx returns html instead of json response

Dan G. Switzer, II dan.switzer at givainc.com
Mon Nov 7 16:08:16 UTC 2022


The "internal" keyword indicates only internal request can access the 
location:

http://nginx.org/en/docs/http/ngx_http_core_module.html#internal

So hitting ttp://mydomain.com/api/v1/*  with CURL would never hit this 
location.

Remove the "internal" keyword, reload Nginx and try it again.

-Dan

On 11/7/2022 10:29 AM, Kaushal Shriyan wrote:
> Hi,
>
> I am running the nginx version: nginx/1.22 as a reverse proxy server 
> on CentOS Linux release 7.9.2009 (Core). Is there a way to return json 
> response when i hit http://mydomain.com/api/v1/* 
> <https://url.emailprotection.link/?bwxIfDuJKR1YH1mqneKAbav55uYd8-63cvdvlSLvw0mVdAEtaFGRd2iiGoI8nWnhImkBUGplq84IGc2dX0eDK2g~~> 
> instead of the html response.
>
> location /api/v1/* {
>     internal;
>     add_header 'Content-Type' 'application/json charset=UTF-8';
>
>     error_page 502 '{"error": {"status_code": 502,"status": "Bad 
> Gateway"}}';
> }
>
> But whenever I try to send a request to /api/v1/users via curl I get 
> the HTML source code in response instead of JSON response.
>
> Please guide me. Thanks in advance. I look forward to hearing from you.
>
> Best Regards,
>
> Kaushal
>
>
>
> _______________________________________________
> nginx mailing list --nginx at nginx.org
> To unsubscribe send an email tonginx-leave at nginx.org

-- 
Dan G. Switzer, II
Giva, Inc.
Email:dan.switzer at givainc.com
Web Site:http://www.givainc.com

See Our Customer Successes
http://www.givainc.com/customers-casestudies.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221107/952a2ed8/attachment.htm>


More information about the nginx mailing list