Nginx默认是不允许列出整个目录的。
如需此功能:
__配置实例__
location / {
: autoindex on;
}
指导
[#autoindex autoindex]
[#autoindex_exact_size autoindex_exact_size]
[#autoindex_localtime autoindex_localtime]
Template:Anchor
autoindex
syntax: autoindex [ on|off ]
default: autoindex off
context: http, server, location
激活/关闭自动索引
Template:Anchor
autoindex_exact_size
syntax: autoindex_exact_size [ on|off ]
default: autoindex_exact_size on
context: http, server, location
设定索引时文件大小的单位(B,KB, MB 或 GB) Template:Anchor
autoindex_localtime
syntax: autoindex_localtime [ on|off ]
default: autoindex_localtime off
context: http, server, location
开启以本地时间来显示文件时间的功能。默认为关(GMT时间)
================================
如: 让/var/www/soft 这个目录在浏览器中完成列出.
一、设置目录浏览
1、打开/usr/local/nginx/conf/nginx.conf,找到WebServer配置处,加入以下内容:
location /soft/ {
root /var/www/; 此处为soft的上一级目录
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
2、保存退出,重启nginx服务即可。
[root@localhost Soft]#ps aux | grep -v grep | grep nginx | awk ‘{print $2}’ | xargs kill -9 #结束进程
[root@localhost Soft]#nginx #启动进程
访问你的站的:http://loalhost/soft,就可以列出目录了。
但是这样的话,别人也很容易看到你目录的内容,下面我们像Apache那样为目录加个访问验证。
二、设置访问验证
1、创建类htpasswd文件
[root@localhost Soft]#wget -c http://jafee.net/Soft/InstallPack/htpasswd.sh
[root@localhost Soft]#bash htpasswd.sh
提示输入用户名、密码、及认证文件名,脚本会自动生成认证文件,这里默认路径是保存在了/usr/local/nginx/conf 下,如果你的nginx目录不是这里,可以修改htpasswd.sh替换你的nginx目录。
我这里是:/usr/local/nginx/conf/test.conf #记下此路径
2、为Nginx添加auth认证配置
location ^~ /soft/
{
auth_basic “MyPath Authorized”;
auth_basic_user_file /usr/local/nginx/conf/test.conf; #这里写前面脚本返回的文件路径;
}
#”MyPath Authorized”为提示信息,可以自行修改。
3、修改好配置后,重启nginx,访问http://localhost/soft/ 就会提示输入用户名和密码,认证成功后,即可列出目录。
4、需要注意的是,加上认证之后该目录下的php文件将不会被解析,会让你下载,如果要使其能够解析php可以将上面的配置改为:
location ^~ /soft/ {
location ~ .*\.(php|php5)?$ {
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}
auth_basic “Authorized users only”;
auth_basic_user_file /usr/local/nginx/conf/test.conf ;
}
来自:http://wiki.nginx.org/NginxNgxFancyIndex 和 http://www.huzs.net/?p=688
========================================
1.在配置文件中添加验证语句:
添加auth_basic "auth user" //名字任起
auth_basic_user_file /etc/nginx/htpasswd.conf //目录自己定
2.创建上面所定的目录/etc/nginx/htpasswd.conf
利用apache所带的密码生成工具htpasswd(密码必须是crypt加密的)
/usr/bin/htpasswd -nb user passwd
or
/usr/bin/htpasswd -c /etc/nginx/htpasswd.conf user
3.修改配置文件
- server {
- listen 80;
- server_name localhost;
- # auth_basic "auth user";
- # auth_basic_user_file /etc/nginx/htpasswd.conf;
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root /mnt/ ;
- # auth_basic "auth user";
- # auth_basic_user_file /etc/nginx/htpasswd.conf;
- index index.php index.html index.htm;
-
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 ~ ^/admin/.* {…} 保护admin目录下的所有文件。如果你只设了/admin/ 那么直接输入/admin/index.php还是可以访问并且运行的。
^/admin/.* 意为保护该目录下所有文件。当然,只需要一次认证。并不会每次请求或每请求一个文件都要认证一下。
相关推荐
nginx sticky是nginx的module,可以实现基于cookie的负载均衡。 下载后,在编译安装nginx时,用--add-module... ./configure --prefix=/usr/local/nginx-1.6.0 --add-module=../nginx-sticky-module-1.25 --without-...
--> nginx-1.21.6 ======================== 在网上查找半天都只有教程,没有可免费下载的版本,深知没有积分遍地找资源的痛苦,无奈之下只好自己按照教程一步一个坑编译出来的,供大家免费下载使用。(无毒放心使用...
nginx autoindex美化,目录树美化,linux文件浏览器,不同的实现方式和样式,多种选择
资源说明: 1. 采用nginx最新版编译,包含最新的nginx-http-flv-module,以及基础...1. 将压缩包解压到D:\nginx-1.19.3目录下 2. 使用cmd命令打开DOS,并切换到D:\nginx-1.19.3 3. 使用nginxservice.exe install安装
在windows 7 64位 环境下使用nginx的nginx-http-flv-module搭建flv视频流播放所有的安装包,参考:https://blog.csdn.net/qq_33071429/article/details/102628008
windows平台nginx编译nginx-http-flv-module,可直接运行,基于nginx-1.17.10编译
nginx带nginx-http-flv模块,包含所有rtmp功能,我自己在windows下编译的,直接可用,用的是最新版的1.19.4版本
nginx-rtmp模块源码包nginx-rtmp-module-master
nginx-http-flv-module-1.2.10(包含nginx-rtmp-module)
nginx-rtmp-win64;nginx-rtmp-win64 nginx-rtmp-win64 nginx-rtmp-win64 nginx-rtmp-win64 nginx-rtmp-win64nginx-rtmp-win64
此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
windows下编译nginx-http-flv-moudle,编译好的,下载开箱可用,作者亲测。用于直播推流,浏览器flvjs播放视频,支持无插件flash播放。
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
nginx-1.18.0-2.el7.ngx.x86_64.rpm安装包(含有部署手册) nginx-1.18.0-2.el7.ngx.x86_64.rpm安装包(含有部署手册) nginx-1.18.0-2.el7.ngx.x86_64.rpm安装包(含有部署手册) nginx-1.18.0-2.el7.ngx.x86_64.rpm...
基于nginx1.19.3版本,已编译好nginx-http-flv-module,开箱即用。鄙视那些收C币的。
Sticky是nginx的一个模块,它是基于cookie的一种nginx的负载均衡解决方案,通过分发和识别cookie,来使同一个客户端的请求落在同一台服务器上,默认标识名为route (a)客户端首次发起访问请求,nginx接收后,发现...
1、最新版 nginx-http-flv-module(windows可执行程序,含nginx 1.19.3,http-flv-module:1.2.7) 2、内含说明文档,请下载查看。 3、请勿放置于中文路径下,否则无法启动
windows服务注册: 1. 将压缩包解压到D:\nginx-1.19.3目录下 2. 使用cmd命令打开DOS,并切换到D:\nginx-1.19.3 3. 使用nginxservice.exe install安装 若需要自定义路径,注意在nginxservice.xml文件中修改路径