一旦我以前看到过这种情况,当我输入一个URL http://test.com/test/
,而不是给予我一个html页面,它给了我一个'文件浏览器'一样的界面来浏览给定位置的所有文件。
我认为它可能是一个nginx模块,可以在位置上下文中启用。nginx.conf
文件:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 122.97.248.252;
location /test {
root /home/yozloy/html/;
autoindex on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
更新error.log
2012年5月19日20:48:33【错误】20357#0:*72打开()“/home/yozloy/html/test”失败(2:无此类文件或目录),客户端:服务125.43.236.33122.97.248.252请求:“GET /测试HTTP/1.1”,主机:“unicom2.markson.hk
我一定是误解了位置/test
的意思,我以为它的意思是当我键入http://example.com/test时,它将访问根字典/home/yozloy/html/
7条答案
按热度按时间fhg3lkii1#
您应该试试ngx_http_autoindex_module。
将
autoindex
选项设置为on
。默认值为off
。您的示例配置应该没问题
如果没有
autoindex
选项,您应该会在没有index.html
档案的目录上,收到以/
结尾的要求时,收到错误403。如果有这个选项,您应该会收到一个简单的清单:**编辑:**更新列表以删除任何测试参考
cwdobuhd2#
所有的答案都包含了部分答案。让我试着把所有的答案合二为一。
在新安装的nginx服务器上快速设置“文件浏览器”模式:
1.编辑nginx的默认配置:
1.将以下内容添加到配置部分:
1.在其中创建文件夹和示例文件:
1.重新启动nginx
1.检查结果:
http://<your-server-ip>/myfolder
,例如http://192.168.0.10/myfolder/n8ghc7c13#
1.列出所有目录的内容
将autoindex选项设置为
on
。默认情况下,该选项处于关闭状态。您的配置文件(
vi /etc/nginx/sites-available/default
)应该如下所示2.仅列出某些特定目录的内容
将autoindex选项设置为
on
。默认情况下,该选项处于关闭状态。您的配置文件(
vi /etc/nginx/sites-available/default
)应该是这样的。
将
path_of_your_directory
更改为您的目录路径希望能帮上忙。
vyswwuz24#
您需要创建
/home/yozloy/html/test
文件夹。或者您可以使用alias
,如下所示:pb3skfrl5#
我试过很多次了。
最后我把
autoindex on;
放在http
里面,但是在server
的外面,这样就可以了。xu3bshqb6#
只需将此部分添加到服务器,就在
location / {
之前kupeojn67#
这些解决方案都不起作用!
我有nginx 1.18.0和使用config /etc/nginx/sites-available/default.我的操作系统:分销商ID:Ubuntu说明:Ubuntu 22.04.1 LTS版本:22.04代号:果酱的
以下是我的配置:
我真的很生气,因为我尝试了一切...但它就是不起作用。我想要的是浏览/家庭/用户/内的一切。当我指的是一切时,我指的是一切!在所有子目录中...