Created
March 17, 2011 11:54
-
-
Save chids/874201 to your computer and use it in GitHub Desktop.
How to set the HTTP accept header based on the file extension in Nginx
This file contains hidden or 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
# Copy the accept header to a variable | |
set $acceptHeader $http_accept; | |
# Does the request end in xml or json? | |
if ($uri ~ ^(.*)\.(xml|json)$) { | |
# Create a new accept header... | |
set $acceptHeader "application/$2"; | |
# ...and remove the extension from the path | |
rewrite ^(.*)\.(xml|json)$ $1 last; | |
} | |
# Set the Accept header for the proxied resource | |
proxy_set_header Accept $acceptHeader; | |
# ...continue with normal proxy conf, host and path mapping etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment