Welcome! Log In Create A New Profile

Advanced

Re: Setting the status code

Dennis Jacobfeuerborn
August 06, 2013 06:20PM
On 06.08.2013 13:31, Richard Kearsley wrote:
> On 06/08/13 04:02, Dennis Jacobfeuerborn wrote:
>
>> Since I determine the reason for the denied access in lua a way to do
>> it there would also help. I already tried "nginx.status = 403"
>> followed by a "nginx.exec('/reason1')" but while the right page is
>> display the status code returned gets reset to 200.
>
>
> Hi
> You can do it in lua.. you need to do it in the header filter stage
> I'm doing something similar but probably not exactly the same
> Hopefully example helps (untested):
>
> set $status_code "";
> location /
> {
> access_by_lua '
> -- your lua script here etc...
> -- if (an error happened) then
> ngx.var.status_code = "403"
> ngx.exec("/error/403.html")
> -- end
> ';
> }
>
> location /error
> {
> root html/error;
> header_filter_by_lua '
> if ngx.var.status_code ~= "" then
> ngx.status = ngx.var.status_code
> end
> ';
> }

That did the trick, thanks!

What I basically wound up doing is:

location /error {
root /var/www/html;
header_filter_by_lua '
ngx.status = 503
';
}

Kind of awkward to be forced to use Lua just for this. There should be a
"status_code <code>" directive to make this possible without requiring
the Lua module.

Regards,
Dennis

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

Setting the status code

Dennis Jacobfeuerborn August 05, 2013 11:04PM

Re: Setting the status code

mex August 06, 2013 02:29AM

Re: Setting the status code

Dennis Jacobfeuerborn August 06, 2013 07:04AM

Re: Setting the status code

dbradfield August 06, 2013 07:32AM

Re: Setting the status code

Dennis Jacobfeuerborn August 06, 2013 06:20PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

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