How to disable direct media file access in nginx or ubuntu for non loggedin users?

How to disable direct media file access in nginx or ubuntu for non loggedin users?