Welcome! Log In Create A New Profile

Advanced

Re: about error_page and named location

Maxim Dounin
November 30, 2012 02:52AM
Hello!

On Fri, Nov 30, 2012 at 10:33:06AM +0800, 任晓磊 wrote:

> 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?

Named location is looked up directly, without executing
server-level rewrite module directives again (which in your above
config will return another 410 error, resulting in default error
being returned).

> 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.

Use text extension to be matched by mime.types, or set
default_type correctly for the location in question
(http://nginx.org/r/default_type).

--
Maxim Dounin
http://nginx.com/support.html

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

about error_page and named location

任晓磊 November 29, 2012 09:34PM

Re: about error_page and named location

Maxim Dounin November 30, 2012 02:52AM

Re: about error_page and named location

Ruslan Ermilov November 30, 2012 05:04AM

Re: about error_page and named location

任晓磊 November 30, 2012 11:16AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 236
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready