【问题标题】:Don't Allow File Download Without htpasswd nginx不允许在没有 htpasswd nginx 的情况下下载文件
【发布时间】:2023-03-12 15:01:01
【问题描述】:

我已经使用 .htpasswd 文件在 Nginx 上成功设置了 auth_basic。但是,如果有人猜到了文件名,他们仍然可以使用 wget 下载文件,或者只需使用浏览器提供 URL,即使他们没有成功登录。

如何防止有人在未登录的情况下下载文件?

这是我在 nginx 中的 default-ssl 配置文件:


root /var/www/html;
index index.html index.htm index.php;

ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

ssl_session_timeout 5m;

ssl_protocols SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:!LOW:+SSLv3:+EXP;
ssl_prefer_server_ciphers on;

# /dir/dir w/basic auth
location ~ ^/(?P<mydir>.*)/$ {
    auth_basic              "Restricted";
    auth_basic_user_file    $document_root/$mydir/.htpasswd;
    autoindex on;
    allow all;
}
    # prevent listing of .htpasswd
    location ~ /\. {
            deny all;
    }

【问题讨论】:

    标签: nginx download password-protection .htpasswd


    【解决方案1】:

    我认为由于您只保护了文件夹,而不保护文件,请尝试删除美元符号以使其与文件夹下的所有内容匹配

    location ~ ^/(?P<mydir>.*)/$ {}
    

    到

    location ~ ^/(?P<mydir>.*)/ {}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 2017-09-15
      相关资源
      最近更新 更多