0

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.

Ted Lyngmo
125k7 gold badges93 silver badges156 bronze badges
asked Mar 4, 2025 at 12:03
20
  • Could it be the double quotes that causes the failure? What does it say if you make it if ($vod_enable_encryption = yes) {? Commented Mar 4, 2025 at 12:21
  • Is the ngx_http_rewrite_module loaded? Commented Mar 4, 2025 at 12:22
  • Hi. Removing the quotes produces the same error. Commented Mar 4, 2025 at 12:28
  • Hi. How do i check if the module is loaded ?. I'm using a docker Alpine image. Do I need to install it separately ? Commented Mar 4, 2025 at 12:34
  • No idea, I just read the nginx config documentation for conditions but I don't know how to load the necessary module or check if it's loaded. Where do you assign yes to vod_enable_encryption? You mention "environment variable", but I don't think environment variables are accessible from ngnix config files. I could be wrong though. Commented Mar 4, 2025 at 12:37

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.