I am using nginx as a proxy server to send the requests to backend pool members .
I have a header -- Content-Type: multipart/form-data; boundary="21ad608c-8e00-4c0c-8a06-5ed1280e9532" The boundary value in the header changes all the time.
How can I do a header check for only "Content-Type: multipart/form-data;" value and route the requests to the backend. when I do a print of $http_content_type value , everything including boundary value is getting printed . I am not able to do an if check on just " Content-Type: multipart/form-data; " value .
Can I put a wild card in the nginx config like -- "multipart/form-data; * " to pass the if loop ?
Please let me know.
An Nginx wildcard? Yes, sort of, via a regex:
if ($http_content_type !~ '^multipart/form-data;') deny-the-request
This means that the Content-Type must start with multipart/form-data;. After that, any boundary=...whatever... is allowed.
Complete example:
location /-/upload-public-file {
limit_except POST OPTIONS {
deny all;
}
if ($http_content_type !~ '^multipart/form-data;') {
return 406; # status code Not acceptable
}