How to make uploads available only to logged-in users

for example:

I posted in this post

https://example.com/aaa/111.txt

Guest users can see this post, But if download 111.txt, the guest user must log in.

/aaa/111.txt provided by nginx.

I have try Discourse SSO in Nginx , Seems to have failed.