nginx direct video links help

vl4d

New member
Jul 14, 2018
16
2
3
hello..i am trying like months now to do this but nothing :/ i want to make my direct video links on my dedicated server to be working only in embed mode and only one X domain in direct link to show the 404 error nginx,
i am using ubuntu and nginx..
thanks!!!!

(i try this but still noting https://prnt.sc/u4caxh the videos is root/q(folder/X(folder)/video,mp4 )
 

MrSam_1

Well-known member
Administrative
Trusted Seller
Dec 1, 2018
24,103
27,358
120
First of all get rid of http/https from Allow_Origin directive.
Do not forget to modify http_origin to match your site/sites. http_origin sites can be with or without www
Implement following code to your location mp4 block and adapt it (it is only a head start example on how it should look like)

Code:
    set $cors '';
    if ($http_origin ~ '^https?://(localhost|site\.com|www\.alt.web\.com|www.\.example\.net)') {
            set $cors 'true';
    }

    if ($cors = 'true') {
            add_header 'Access-Control-Allow-Origin' "$http_origin" always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
            # required to be able to read Authorization header in frontend
            #add_header 'Access-Control-Expose-Headers' 'Authorization' always;
    }

    if ($request_method = 'OPTIONS') {
            # Tell client that this pre-flight info is valid for 20 days
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
    }
# do not forget to add other methods GET PUT ...
 

Bazooka

Active member
Jul 22, 2019
350
177
43
Easiest method, but less secure:

Code:
    location ~ \.mp4$ {
        valid_referers none blocked yourwebsite.com;
        if ($invalid_referer) {
            return    403;
        }

Try this and let me know if it worked.
 

vl4d

New member
Jul 14, 2018
16
2
3
First of all get rid of http/https from Allow_Origin directive.
Do not forget to modify http_origin to match your site/sites. http_origin sites can be with or without www
Implement following code to your location mp4 block and adapt it (it is only a head start example on how it should look like)

Code:
    set $cors '';
    if ($http_origin ~ '^https?://(localhost|site\.com|www\.alt.web\.com|www.\.example\.net)') {
            set $cors 'true';
    }

    if ($cors = 'true') {
            add_header 'Access-Control-Allow-Origin' "$http_origin" always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
            add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
            # required to be able to read Authorization header in frontend
            #add_header 'Access-Control-Expose-Headers' 'Authorization' always;
    }

    if ($request_method = 'OPTIONS') {
            # Tell client that this pre-flight info is valid for 20 days
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain charset=UTF-8';
            add_header 'Content-Length' 0;
            return 204;
    }
# do not forget to add other methods GET PUT ...
i try this nothing. https://prnt.sc/ub45x6
 

vl4d

New member
Jul 14, 2018
16
2
3
Easiest method, but less secure:

Code:
    location ~ \.mp4$ {
        valid_referers none blocked yourwebsite.com;
        if ($invalid_referer) {
            return    403;
        }

Try this and let me know if it worked.
this is just dont load the direct link but the link is open with player not the error from nginx :) and what ever domain i put is the same

this code is weird the 403 error is working only on chrome lol
 
Last edited:

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu