Welcome! Log In Create A New Profile

Advanced

conditional headers

Posted by deanpence 
conditional headers
July 11, 2010 05:06AM
Hi all,

I'm actually migrating from lighttpd to nginx, and I'm trying to preserve some old conditionals.

In lighttpd, I have something like this:

[code]
$HTTP["referer"] =~ "^http://(labs\.|etc\.)example.com/" {
$HTTP["url"] =~ "\.(eot|otf|svg|woff|ttf|ogg|oga|ogv|m4a|m4v|mp3|mov|mp4|mov)$" {
setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )
}
}
[/code]

I attempted this in nginx:

[code]
location ~ "\.(eot|otf|svg|woff|ttf|ogg|oga|ogv|m4a|m4v|mp3|mov|mp4|mov)$" {
if ($http_referer ~ "^http://(labs\.|etc\.)example.com/") {
add_header Access-Control-Allow-Origin *;
}
}
[/code]

But this did absolutely nothing. No header appeared. Apparently, "add_header" does nothing (and is in error) inside an "if" directive.

I want to add this header so I can serve web fonts and multimedia to several sites while being consistent with the license these files are offered under. I know it's trivial to get around these rules, but I think it's my responsibility to take even small steps to comply with these very reasonable licenses.

Does anyone have any idea how I can do this in nginx?
Re: conditional headers
July 21, 2010 10:00AM
Okay, let's simplify.

In lighttpd, I'm doing something like this:

[code]
# Referer is example.com:
$HTTP["referer"] == "http://example.com/" {

# Request for a font:
$HTTP["url"] =~ "\.(eot|otf|svg|woff|ttf)$" {

# Set the header that Firefox requires to use the font:
setenv.add-response-header = ( "Access-Control-Allow-Origin" => "*" )

}

}
[/code]

In nginx, does anyone have an idea how to add a response header based on the presence of a request header?



Edited 1 time(s). Last edit at 07/21/2010 10:02AM by deanpence.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

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