I have an environment variable set as
vod_enable_encryption = yes
which I'm attempting to check using an If block in nginx.conf.
Nginx isn't able to resolve the condition and throwing the following error :
invalid condition "yes"
The error is thrown at the following 2 location blocks:
The 1st block where The variable is checked is within the location block as follows:
location ~ ^/vod/([^/]+)/.+\.(m3u8|ts)$ { vod_mode local; vod hls; vod_base_url ""; if ($vod_enable_encryption = "yes") { set $stream_uuid $1; vod_hls_encryption_method aes-128; vod_secret_key "$rtmp_secret $stream_uuid"; set_hmac_sha1 $sig $rtmp_secret "$cookie_sessionid $stream_uuid"; if ($http_authorization) { set_hmac_sha1 $sig $rtmp_secret "$http_authorization $stream_uuid"; } set_encode_base64 $sig $sig; vod_hls_encryption_key_uri "~ ^/vod/([^/]+)/encryption.key?s=$sig"; } } The 2nd block where The variable is checked is outside the location block as follows:
if ($vod_enable_encryption = "yes") { location ~ ^/vod/([^/]+)/encryption\.key$ { vod_mode local; vod hls; vod_base_url ""; set $stream_uuid $1; set $user_sig $arg_s; set_hmac_sha1 $sig $rtmp_secret "$cookie_sessionid $stream_uuid"; if ($http_authorization) { set_hmac_sha1 $sig $rtmp_secret "$http_authorization $stream_uuid"; } set_encode_base64 $sig $sig; if ($sig != $user_sig) { return 403; } auth_request /authorize; vod_hls_encryption_method aes-128; vod_secret_key "$rtmp_secret $stream_uuid"; } } I'm unable to solve the issue above and spent quite sometime on it. Upon reading more, I realized that One must try avoiding using If conditions in nginx as much as possible. I couldn't figure an alternative implementation. Help appreciated.
if ($vod_enable_encryption = yes) {?ngx_http_rewrite_moduleloaded?yestovod_enable_encryption? You mention "environment variable", but I don't think environment variables are accessible from ngnix config files. I could be wrong though.