Nginx

How to Set Response Headers in Nginx on Debian

Add Header Using the Nginx add_header directive can lead to duplicate header entries. Consider the following configuration file: server { ... location = /ok { add_header Content-Type application/json; return 200 '{"result":"ok"}'; } } For me this resulted in the following response: $ curl -iI https://api.primesite.dev/ok HTTP/1.1 200 OK Date: Sat, 10 Oct 2020 03:40:20 GMT Content-Type: application/octet-stream Content-Type: application/json Content-Length: 15 Notice the duplicate Content-Type headers above. The first one with the value of “application/octet-stream” comes from my main nginx.