zoukankan      html  css  js  c++  java
  • nginx文件目录权限设置


    1.有时我们web服务器上的某个文件夹只允许特定人员访问,这时我们需要在nginx配置文件中配置该文件夹的访问权限。

    2.生成用户名单
    在nginx中我们使用htpasswd来生成用户名单
    下载这个python文件:http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py (nginx wiki里推荐的)
    运行示例:

    chmod 777 htpasswd.py
    ./htpasswd.py -c -b htpasswd username password

    #-c为生成文件 htpasswd为文件名

    nginx 的 http auth basic 的密码是用 crypt(3) 加密的
    我们把生成的htpasswd文件放到/etc/nginx目录中,修改权限chmod 400 htpasswd来保护一下该文件。

    3.修改nginx配置文件

    server {
    server_name www.test.com;
    root /usr/share/nginx/html;
    location /devdoc {
    autoindex on;#显示文件列表
    index index.html index.htm;#默认首页
    charset utf-8;#编码
    auth_basic "Restricted";#访问权限类型
    auth_basic_user_file /etc/nginx/htpasswd;#用户名单
    }
    }

    重启nginx即可。访问网站www.test.com/devdoc,需要输入我们设置的用户名密码登录才能访问文件。如下图所示:

  • 相关阅读:
    CF786E ALT
    CF704D Captain America
    [NOI2016]循环之美
    「PKUWC2018」猎人杀
    [HNOI2019]JOJO
    博客已转移
    $20200203$的数学作业
    20200202的数学作业
    NOIp 2016 选课 (DP)
    Luogu P2574 XOR的艺术 (线段树)
  • 原文地址:https://www.cnblogs.com/shijingjing07/p/6237809.html
Copyright © 2011-2022 走看看