Return text with NGINX

Maybe you’re want to display the simplest message to a viewer. You may opt to display plain text. NGINX provides a simple solution using the example code below. Simply choose the path and return your text.

location / {
    #So browsers won't download a file with the text
    add_header Content-Type text/plain;
    #Displays the actual text
    return 200 'Your text here';
}

Return accepts 2 arguments. First one is HTTP Code and the last one is the text you want to show. The "Content-Type" header defines the type of content the browser will expect to receive. When the browser sees that the Content-Type is "text/plain", it will know to display the content as plain text.