I need a little help with nginx conf setup. My config is basically this...
map $http_apikey $api_client_name {
default "";
"CLIENT_ID" "client_one";
}
server {
access_log /dev/stdout main;
listen 443 ssl;
server_name localhost;
# TLS config
ssl_certificate /etc/nginx/ssl/cert.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_protocols TLSv1.2 TLSv1.3;
proxy_intercept_errors on; # Do not send backend errors to the client
default_type application/json; # If no content-type then assume JSON
location ~ ^/index-$http_apikey {
if ($http_apikey = "") {
return 401; # Unauthorized
}
if ($api_client_name = "") {
return 403; # Forbidden
}
proxy_pass http://elasticsearch:9200;
}
....
The idea is to get the http_apikey
from the header information on POST and use it as a part of the link. However the VAR, http_apikey
, has upper case letters in it as well as lower case letters and numbers. The URI is expected to be in all lowercase though, so essentially:
location ~ ^/index-$http_apikey.lower() {
if ($http_apikey = "") {
return 401; # Unauthorized
}
if ($api_client_name = "") {
return 403; # Forbidden
}
proxy_pass http://elasticsearch:9200;
}
location ~ ^/index-$http_apikey.lower()
Is there a way to do this in nginx? Like in bash I would just ${http_apikey,,}
... is there an nginx equivalent?
Thanks