Skip to content

Instantly share code, notes, and snippets.

@evandhoffman
Last active October 8, 2015 21:24
Show Gist options
  • Save evandhoffman/9536766 to your computer and use it in GitHub Desktop.
Save evandhoffman/9536766 to your computer and use it in GitHub Desktop.
Nginx add_header
# Nginx will fail to start and will throw an error like this:
# Reloading nginx configuration: nginx: [emerg] "add_header" directive is not allowed here in /etc/nginx/sites-enabled/fail1.conf:39
server {
listen 8080 default;
server_name _;
root /var/www/html ;
if ($http_host = 'evan.com') {
add_header 'X-Evan-A' '1';
}
location / {
}
}
# This works
server {
listen 8080 default;
server_name _;
root /var/www/html ;
add_header 'X-Evan-A' '1';
location / {
}
}
# This works
server {
listen 8080 default;
server_name _;
root /var/www/html ;
location / {
if ($http_host = 'evan.com') {
add_header 'X-Evan-A' '1';
}
}
}
# This works
server {
listen 8080 default;
server_name _;
root /var/www/html ;
location / {
add_header 'X-Evan-A' '1';
}
}
@jochem
Copy link

jochem commented Aug 28, 2014

Good question, do you have an answer yet? ;)

@algermissen
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment