Why might a return statement in nginx.conf return a plain text file location to the browser instead of the actual file to be rendered?

Solution 1:

The URL after return nnn is treated only as a target URL for redirection code (301, 302, 303, 307 and 308 status codes). The documentation doesn't clearly tell what it does when code is something else.

To get an error page in your case, use the following:

if ($request_method !~ ^(GET|HEAD|POST)$) {
    return 405;
}

error_page 405 /html/405.html;

This will tell nginx to send /html/405.html when status code 405 is returned.