For rejecting some unfriendly access, I use 410 status code for them. The config is below:<div><br></div><div><div style="font-family:arial,sans-serif;font-size:14px">error_page 410 /410;</div><div style="font-family:arial,sans-serif;font-size:14px">
if (xxx) {</div><div style="font-family:arial,sans-serif;font-size:14px"> return 410;</div><div style="font-family:arial,sans-serif;font-size:14px">}</div><div style="font-family:arial,sans-serif;font-size:14px"><br></div>
<div style="font-family:arial,sans-serif;font-size:14px">location /410 {</div><div style="font-family:arial,sans-serif;font-size:14px"> more_set_headers "Content-Type: text/html;charset=utf8;";<div><span style="white-space:pre-wrap"> </span>return 410 '$remote_addr 禁止访问云云';</div>
<div>}</div><div><br></div><div>When I access it for testing purpose, I got</div><div><div><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"></div><div><html></div><div><head><title>410 Gone</title></head></div>
<div><body bgcolor="white"></div><div><h1>410 Gone</h1></div><div><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</div>
<div></body></div><div></html></div></div><div><br></div><div>If I use error_page 410 @410; and location @410{...} , it works correctly, and serves a page with my own message.</div><div><br></div><div>So,</div>
<div>1st, What's the differences between norma location and named location, in this context?</div><div>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.</div>
</div>-- <br>Ren Xiaolei<br>
</div>