Opened 6 months ago

Closed 6 months ago

#2324 closed defect (invalid)

error_page disables add_header

Reported by: RekGRpth@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.19.x
Keywords: Cc:
uname -a: Linux nginx 5.13.0-30-generic #33-Ubuntu SMP Fri Feb 4 17:03:31 UTC 2022 x86_64 Linux
nginx -V: nginx version: nginx/1.21.7
built by gcc 10.3.1 20211027 (Alpine 10.3.1_git20211027)
built with OpenSSL 1.1.1l 24 Aug 2021
TLS SNI support enabled
configure arguments: --add-dynamic-module='modules/ngx_devel_kit modules/echo-nginx-module modules/encrypted-session-nginx-module modules/form-input-nginx-module modules/iconv-nginx-module modules/nginx_csrf_prevent modules/nginx-jwt-module modules/nginx-push-stream-module modules/nginx-upload-module modules/nginx-upstream-fair modules/nginx-uuid4-module modules/ngx_brotli/filter modules/ngx_brotli/static modules/ngx_http_auth_basic_ldap_module modules/ngx_http_captcha_module modules/ngx_http_handlebars_module modules/ngx_http_headers_module modules/ngx_http_htmldoc_module modules/ngx_http_json_module modules/ngx_http_mustach_module modules/ngx_http_sign_module modules/ngx_http_substitutions_filter_module modules/ngx_http_upstream_session_sticky_module modules/ngx_http_zip_var_module modules/ngx_postgres modules/set-misc-nginx-module modules/ngx_http_auth_pam_module modules/ngx_http_evaluate_module modules/spnego-http-auth-nginx-module modules/ngx_http_response_body_module modules/headers-more-nginx-module modules/ngx_http_remote_passwd modules/ngx_http_json_var_module modules/ngx_http_time_var_module modules/ngx_http_error_page_inherit_module modules/ngx_http_include_server_module' --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --group=nginx --http-client-body-temp-path=/var/tmp/nginx/client_body --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/tmp/nginx/proxy --http-scgi-temp-path=/var/tmp/nginx/scgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --lock-path=/run/nginx/nginx.lock --modules-path=/usr/local/lib/nginx --pid-path=/run/nginx/nginx.pid --prefix=/etc/nginx --sbin-path=/usr/local/bin/nginx --user=nginx --with-cc-opt='-Wextra -Wwrite-strings -Wmissing-prototypes -Werror -Wno-discarded-qualifiers' --with-compat --with-debug --with-file-aio --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-pcre --with-pcre-jit --with-poll_module --with-select_module --with-stream=dynamic --with-stream_geoip_module=dynamic --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads

Description

error_page disables add_header
compare

location =/one {
    add_header name value;
    return 303 OK;
}

and

location @error {
    return 200 OK;
}
location =/two {
    add_header name value;
    error_page 303 = @error;
    return 303 OK;
}

if request one location, it adds header name with value value
but if request two location, it does not add header

Change History (2)

comment:1 by RekGRpth@…, 6 months ago

also compare

add_header name1 value1;
location =/one {
    add_header name2 value2;
    return 303 OK;
}

and

location @error {
    return 200 OK;
}
add_header name1 value1;
location =/two {
    add_header name2 value2;
    error_page 303 = @error;
    return 303 OK;
}

if request one location, it adds header name2 with value value2
but if request two location, it adds header name1 with value value1

comment:2 by Maxim Dounin, 6 months ago

Resolution: invalid
Status: newclosed

The add_header directive adds headers to the response returned in the particular configuration context. In the configuration

location =/one {
    add_header name value;
    return 303 OK;
}

the name: value header is expected to be added. In contrast, in the configuration

location @error {
    return 200 OK;
}
location =/two {
    add_header name value;
    error_page 303 = @error;
    return 303 OK;
}

the response is returned in the location @error context, where no add_header directives are configured, so no additional headers are returned. Similarly, in the configuration

location @error {
    return 200 OK;
}
add_header name1 value1;
location =/two {
    add_header name2 value2;
    error_page 303 = @error;
    return 303 OK;
}

the response is returned in the location @error context, where add_header name1 value1; inherited from the server level instructs nginx to add the name1: value1 header.

For more information consider the location directive description, as well as Beginner’s Guide and the How nginx processes a request introductory article. If you have further questions on how nginx works, consider support options available.

Note: See TracTickets for help on using tickets.