Nginx Return Custom Json

14 Januari 2021 • 1 menit untuk membaca artikel ini

Nginx return custom json

server {
  listen 80 default_server;
  server_name _;

  root /var/www/html;
  index index.html;

  location / {
    default_type application/json;
    return 200 '{"code":"0", "message": "I am alive"}';
  }
}

Test:

▶ curl -iL anuku.domainku.tld
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sun, 14 Nov 2021 11:39:17 GMT
Content-Type: application/json
Content-Length: 37
Connection: keep-alive
Vary: Accept-Encoding

{"code":"0", "message": "I am alive"}%
Techlinuxnginx

Sumarsono

System Administrator
Kembali ke atas

Nginx Basic Auth Dengan Pengecualian>>

<<Limit Sudoer Command