nginx add headers when returning 400 codes

前端 未结 1 1283
北海茫月
北海茫月 2020-12-03 00:46

I\'m developing an ember.js app with a laravel backend. I\'m trying to return http error codes with php if something goes awry. I\'ve noticed that when issue a PUT request a

相关标签:
1条回答
  • 2020-12-03 01:20

    For nginx >= 1.7.5

    Append "always" to the header definition:

    add_header 'Access-Control-Allow-Origin' '*' always;
    

    For nginx < 1.7.5

    According to the nginx official document of ngx_header_module, the add_header can't work when response code is 400

    syntax:     add_header name value;
    default:    —
    context:    http, server, location, if in location
    
    
    Adds the specified field to a response header provided that the response code equals 
    200, 201, 204, 206, 301, 302, 303, 304, or 307. A value can contain variables.
    

    In another way, you can try the HttpHeadersMoreModule, which is more powerful.

    0 讨论(0)
提交回复
热议问题