Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return a string using the Nginx container

Tags:

nginx

I am using the Nginx container to host a SPA application in Kubernetes.

Aside from the static files hosted for the SPA app, I also need to host the routes for health checks. So, the route /health/startup needs to return the text healthy when a GET request is sent to it.

I suppose I could just make a folder called "health" and then put a file in it called startup with the text healthy in it. But that seems a bit odd to me. And I worry that if the file structure may get changed and that then my health checks will start failing.

Is there a way, using the Nginx container to return a given value (ie "healthy")when a request comes to a specific route? (And not mess up the rest of my static file serving that is going on.)

like image 797
Vaccano Avatar asked Dec 30 '25 14:12

Vaccano


1 Answers

Yes you can, in the configuration you are importing for the server, you can just do this:

location /health/startup {
    add_header Content-Type text/plain;
    return 200 'healthy';
}
like image 183
Alberto Sinigaglia Avatar answered Jan 01 '26 05:01

Alberto Sinigaglia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!