Nginx
Nginx
Nginx: Retourner un json avec un custom location
Nginx: Retourner un json avec un custom location
Bien pratique pour faire des tests ou tout simplement pour renvoyer des données spécifiques par domaine.
Ajouter le location suivant dans un vhost
location /test {
default_type application/json;
return 200 '{"status":"success", "result":"nginx test json", "env":"production", "bar": "foo"}';
}Cela permettra à Nginx de retourner le contenu json suivant
$ curl -I http://127.0.0.1/test
HTTP/1.1 200 OK
Server: nginx/1.31.4
Date: Sat, 29 Aug 2026 15:30:11 GMT
Content-Type: application/json
Content-Length: 82
Connection: keep-alive
$ curl -s http://127.0.0.1/test | jq
{
"status": "success",
"result": "nginx test json",
"env": "production",
"bar": "foo"
}