怎么查看php目录权限设置密码,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为文件名

printf "fss:$(openssl passwd -crypt 123456)\n" >> /data/auth/users

nginx 的 http auth basic 的密码是用 crypt(3) 加密的

我们把生成的htpasswd文件放到/etc/nginx目录中,修改权限chmod 400 htpasswd来保护一下该文件。

切记,htpasswd文件不能放在/root目录下,否则会一直报错13: Permission denied,浏览器会提示500错误

3.修改nginx配置文件

针对特定目录加密location ~ ^/shell/.*

{

autoindex on;

autoindex_exact_size off;

autoindex_localtime on;

auth_basic "Server Auth";

auth_basic_user_file /usr/local/nginx/conf/vhost/htpasswd;

}

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

基于整个网站的认证,auth_basic要在php解释之前。server {

listen 80;

server_name www.wkii.org akii.org;

root /www/akii;

index index.html index.htm index.php;

auth_basic "input you user name and password";

auth_basic_user_file /usr/local/nginx/conf/vhost/nginx_passwd;

location ~ .php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

location ~ /\.ht {

deny all;

}

access_log /logs/akii.org_access.log main;

针对目录的认证,在一个单独的location中,并且在该location中嵌套一个解释php的location,否则php文件不会执行并且会被下载。auth_basic在嵌套的location之后。server {

listen 80;

server_name www.wkii.org akii.org;

root /www/akii;

index index.html index.htm index.php;

location ~ ^/admin/.* {

location ~ \.php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

auth_basic "auth";

auth_basic_user_file /usr/local/nginx/conf/vhost/auth/admin.pass;

}

location ~ .php$ {

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

location ~ /\.ht {

deny all;

}

access_log /logs/akii.org_access.log main;

}

wget下载ftp或http服务器上需要用户名密码验证的文件

用户自己搭建的ftp服务器或设置了用户名密码验证的http服务器,都是需要验证后才能下载,没法直接通过wget 下载,必须加上验证参数才行。

FTP下:wget --ftp-user=帐号 --ftp-password=密码 ftp://ip或域名/目录/文件名

HTTP下:wget --http-user=帐号 --http-password=密码 http://ip或域名/目录/文件名

如果机器上装了lftp,也是一个不粗的选择lftp ip -p port -u user,password登陆ftp服务器

然后get 文件名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值