Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
generate URL for nginx secure_link
@smowtion
Copy link

smowtion commented Mar 27, 2017

Can you share nginx config

@mohammadhosin
Copy link

mohammadhosin commented Jun 5, 2017

	location /securetest {
		   alias html/mhmsecure/securetest;
            secure_link $arg_md5,$arg_expires;
            secure_link_md5 "$secure_link_expires$uri$remote_addr live21.ir";

            if ($secure_link = "") { return 403; }
            if ($secure_link = "0") { return 410; }
        
		}

@nicolasvahidzein
Copy link

nicolasvahidzein commented Sep 10, 2018

You Sir are amazing, thank you for sharing this. I NEVER would have been able to figure this secure link thing alone, you saved me big time. Thank you thank you thank you!!!!

@tahir7us
Copy link

tahir7us commented Aug 6, 2019

Thank you so much, you are the time-saver

@fquero47
Copy link

fquero47 commented Jul 2, 2020

THANKKK you a lot bro.

@batoasnawi1986
Copy link

batoasnawi1986 commented Apr 27, 2022

it not working for different server. like server 1 is where stored the zip file and server 2 were the secure_link.php was configured. please help how to fixed?

@satirovaf
Copy link

satirovaf commented Jul 24, 2022

I know that I'm a little bit later, but I'm having on 403, for each link that I generate.

The PHP is getting the IP and time right, but I still have 403. Any clues?

@bftanase
Copy link
Author

bftanase commented Jul 24, 2022

There are some examples on the nginx docs page on how to generate the md5 hash using linux commands.
http://nginx.org/en/docs/http/ngx_http_secure_link_module.html#secure_link

You could try to compare what you get from php with this and see if there's any difference.

@satirovaf
Copy link

satirovaf commented Jul 24, 2022

Thanks for your reply, even generating the md5 hash in Linux and not at the PHP file, I will getting 403 when trying to serve the video file.

@bftanase
Copy link
Author

bftanase commented Jul 24, 2022

Then, maybe there's something wrong with the nginx config.

@satirovaf
Copy link

satirovaf commented Jul 24, 2022

I'm using the config provided above, and all the PHP is running ok on the subdomain. Also tried the config from (https://rahul-juneja3.medium.com/how-to-create-secure-download-link-urls-via-nginx-5578a0db5913), with and without the 443 SSL from certbot.

@bftanase
Copy link
Author

bftanase commented Jul 24, 2022

Well, at this point, I would look for small typos, maybe the secret is not the same in nginx config and in your php script. Maybe a weird character copy pasted somewhere.

I don't have any other ideas... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment