Welcome! Log In Create A New Profile

Advanced

Re:returning a 302 from ACCESS_PHASE handler

September 10, 2013 09:52PM
I once wrote a similar module, just directly in the handler,
return NGX_HTTP_MOVED_TEMPORARILY;


see:
https://github.com/flygoast/ngx_http_url_hash_module







At 2013-09-11 05:33:31,"Michael Ellery" <mellery451@gmail.com> wrote:
>Hello,
>
>I have an ACCESS_PHASE handler and, in some cases, I want to return a 302 to a different domain. I'm currently doing
>the following:
>
><code>
> ngx_table_elt_t *set_location = ngx_list_push(&r->headers_out.headers);
> if (set_location == NULL) {
> SXEL2("ERROR: failed to add location header");
> return -1;
> }
>
> r->err_status = NGX_HTTP_MOVED_TEMPORARILY;
>
> set_location->hash = 1;
> ngx_str_set(&set_location->key, "Location");
> set_location->value.len = len;
> set_location->value.data = location;
>
> ngx_http_clear_location(r);
>
> ngx_http_finalize_request(r, NGX_HTTP_MOVED_TEMPORARILY);
>
></code>
>
>and then returning NGX_OK from my handler.
>
>This seems to work in the sense that I do get the expected 302 at my client - HOWEVER, I also get a segfault:
>
>2013/09/10 13:26:22 [alert] 28910#0: worker process 29362 exited on signal 11
>
>...which seems to be happening at ngx_http_proxy_module.c:645
>
> ngx_http_set_ctx(r, ctx, ngx_http_proxy_module);
>
>because r->ctx is NULL at this point.
>
>I suspect that calling ngx_http_finalize_request from my handler is causing this, although I have not conclusively
>proven this.
>
>Does someone know if it's possible to return a redirect from ACCESS handlers and, if so, what is the proper way to
>accomplish it?
>
>TIA,
>Mike Ellery
>
>_______________________________________________
>nginx-devel mailing list
>nginx-devel@nginx.org
>http://mailman.nginx.org/mailman/listinfo/nginx-devel
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

returning a 302 from ACCESS_PHASE handler

Michael Ellery 861 September 10, 2013 05:38PM

Re:returning a 302 from ACCESS_PHASE handler

flygoast 528 September 10, 2013 09:52PM

Re: returning a 302 from ACCESS_PHASE handler

Maxim Dounin 404 September 11, 2013 07:36AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 176
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