Nginx Quick Response

September 23, 2018

When working with Nginx it can be tricking to debug. If you are working with difficult redirects I recommend using their debug log. However for quick fixed the tip below works well.

Nginx allows you to return text directly from a code block using the following syntax.

server {
    ...
    location / {
        return 200 'OK';
    }
    ...
}

The cool thing is you can also use this to return an Nginx variable.

server {
    ...
    location / {
        return 200 $uri;
    }
    ...
}

Or a regex variable.

server {
    ...
    location ~ /test/(.*) {
        return 200 $1;
    }
    ...
}

comments powered by Disqus