最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

content restriction - Limit file downloads to logged in users (WP + Nginx)

programmeradmin0浏览0评论

I am looking for a way to restrict access to mp3 files on my site to logged in users only.

The approach listed here sounds pretty much like what I need:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^.*(mp3|m4a)$
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . - [R=403,L]

except how would I convert these .htaccess rules to nginx?

I am looking for a way to restrict access to mp3 files on my site to logged in users only.

The approach listed here sounds pretty much like what I need:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^.*(mp3|m4a)$
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule . - [R=403,L]

except how would I convert these .htaccess rules to nginx?

Share Improve this question edited May 18, 2014 at 5:15 pereyra asked May 18, 2014 at 1:43 pereyrapereyra 4755 silver badges15 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 4

You could do it like this:

location ~ \.(mp3|m4a)$ {
  if ($http_cookie !~ "wordpress_logged_in") {
    return 403;
  }
}

If it is really matters that it is secured (as opposed to just not being "obviously" accessible by the general public), auth should probably also be checked since it's quite easy to send the WP login cookie with the HTTP request, regardless of auth status.

a slight variant of this worked better for me

location /wp-content/uploads/ {if ($http_cookie !~ "wordpress_logged_in") {
    return 403;
  }
}

This prevents all direct access to the uploads folder files unless logged in

发布评论

评论列表(0)

  1. 暂无评论