Welcome! Log In Create A New Profile

Advanced

"add_header" directive is not allowed here

Posted by hsc@miracle.dk 
"add_header" directive is not allowed here
August 13, 2018 09:13AM
Hi

I have this service where I proxy_pass a lot of different locations to different services.
All "locations" in this "server" need to have a lot of add_header lines for cors filtering.
But if I move the add_header from the "location" to the "server" section I get a:
nginx: [emerg] "add_header" directive is not allowed here in

Do I have to have all these "add_header" in each "location" or is there a trick I can do?

server {
listen 80;
server_name example.org;
location /foo {
root /var/www/nginx/html;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
# many lines here with "add_header"
return 204;
}
proxy_pass http://localhost:8080;
}
}

best regards
Hans
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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