about error_page and named location
任晓磊
julyclyde at gmail.com
Fri Nov 30 02:33:06 UTC 2012
For rejecting some unfriendly access, I use 410 status code for them. The
config is below:
error_page 410 /410;
if (xxx) {
return 410;
}
location /410 {
more_set_headers "Content-Type: text/html;charset=utf8;";
return 410 '$remote_addr 禁止访问云云';
}
When I access it for testing purpose, I got
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
<head><title>410 Gone</title></head>
<body bgcolor="white">
<h1>410 Gone</h1>
<p>The requested resource is no longer available on this server and there
is no forwarding address. Please remove all references to this
resource.<hr/>Powered by Tengine
</body>
</html>
If I use error_page 410 @410; and location @410{...} , it works correctly,
and serves a page with my own message.
So,
1st, What's the differences between norma location and named location, in
this context?
2nd, Are there better ways to serve a html page to unfriendly access, and
use nginx's variables in the html? I tried return 410 '$remote_addr
rejected' ,but it gave a application/octet-stream response, browser would
download it instead of display the message in browser window. So I have to
use more headers module to set Content-Type.
--
Ren Xiaolei
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20121130/55574e07/attachment.html>
More information about the nginx
mailing list