Hi all.
So far my config has looked like this:
- adding some haders globally in http block
- then, if necessary, adding / removing some additional headers in location blocks for certain sites (server blocks)
- usually the headers added / removed are the same for all sites, ie. adding extra headers for static files (so the configuration gets repeated throughout sites)
Example:
http {
add_header xxx;
server {
location / {
}
location ~* \.(svg)$ {
add_header xyz;
}
}
server {
location / {
}
}
server {
location / {
}
location ~* \.(svg)$ {
add_header xyz;
}
}
}
Sadly, the more sites, the harder it gets to keep with multiple locations, especially considering the configuration is repeated. So I'd like to make some changes and to go with something like this:
http {
if request = ~* \.(svg)$
add_header xyz;
else
add_header xxx;
server {
location / {
}
server {
location / {
}
}
server {
location / {
}
}
The problem is that location directive cannot be used in http block. I'm thinking about constructing some IF, although don't know how should I approach this. Any ideas?
Thanks in advance!
So far my config has looked like this:
- adding some haders globally in http block
- then, if necessary, adding / removing some additional headers in location blocks for certain sites (server blocks)
- usually the headers added / removed are the same for all sites, ie. adding extra headers for static files (so the configuration gets repeated throughout sites)
Example:
http {
add_header xxx;
server {
location / {
}
location ~* \.(svg)$ {
add_header xyz;
}
}
server {
location / {
}
}
server {
location / {
}
location ~* \.(svg)$ {
add_header xyz;
}
}
}
Sadly, the more sites, the harder it gets to keep with multiple locations, especially considering the configuration is repeated. So I'd like to make some changes and to go with something like this:
http {
if request = ~* \.(svg)$
add_header xyz;
else
add_header xxx;
server {
location / {
}
server {
location / {
}
}
server {
location / {
}
}
The problem is that location directive cannot be used in http block. I'm thinking about constructing some IF, although don't know how should I approach this. Any ideas?
Thanks in advance!