Last active
October 8, 2015 21:24
-
-
Save evandhoffman/9536766 to your computer and use it in GitHub Desktop.
Nginx add_header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This works | |
server { | |
listen 8080 default; | |
server_name _; | |
root /var/www/html ; | |
add_header 'X-Evan-A' '1'; | |
location / { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This works | |
server { | |
listen 8080 default; | |
server_name _; | |
root /var/www/html ; | |
location / { | |
add_header 'X-Evan-A' '1'; | |
} | |
} |
Good question, do you have an answer yet? ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why does nginx not allow an add_header inside an if block inside server{} but does allow it inside location { } ?