New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
How to redirect if user direct access images with nginx?
How do I redirect if a user tries to direct access image files in browser only? I want to keep the ability to embed images with <img src="...">
. How to redirect from
https://img.example.com/c/600x1200_90_webp/img-master/img/2022/01/03/08/04/54/95259215_p0_master1200.jpg
to
https://example.com/detail?id=95259215
This is my nginx conf
location ~ "^/c/600x1200_90_webp/img-master/img/*/*/*/*/*/(?<filename>.+\.(jpg|png))$" {
return 301 https://example.com/detail?id=$filename;
}
Can anyone help fix the code?
Comments
Since the request is the same for both scenarios, I think your best option would be to proxy the images though some sort of script and setup some limits there.
And in nginx only allow from 127.0.0.1.
You can try and check if a referrer is set. If an image is loaded inline the referrer should be the same domain.
Can someone help me fix the redirect code cause it's not working. Here's my full nginx config
You have it backwards, from nginx docs:
$invalid_referer
is an empty string if it is a valid referer (in your case if it is a validserver_name
), you should be checking for 1 instead.You can in theory require a header, but its useless.
Everyone can set and modify the own headers.
Basically you are wasting your own time right now.
Also, disabling image hotlinking is so 2005.
I would assume the primary reason to do so before was bandwidth but that shouldn't be a problem now.