2. Nginx基础模块-目录索引

Nginx基础模块

官方帮助信息
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-lQGMzbNQ-1612796821741)(F:\Linux\老男孩文档\image\image-20200118170255730.png)]

1.Nginx目录索引

http_autoindex_module模块

1.1 语法

默认是不允许列出整个目录浏览下载

syntax: autoindex on | off;

Default: autoindex off;

Contxte: http,server,location

1.2 autoindex常用参数

  • autoindex_exact_size off; //默认为on,显示出文件的确切大小,单位bytes。 修改为off,显示出文件大概大小,单位是KB或者MB或者GB
  • autoindex_localtime on; //默认为off,显示的文件时间为GMT时间。修改为no,显示的文件时间为文件服务器时间
  • charset utf-8,gbk; // 默认中文目录乱码,解决乱码

1.3 代码使用方法

server {
        listen  80;
        server_name localhost;
        location / {
                root /html;
                autoindex on;				//开启目录索引
                autoindex_exact_size off;	//显示出文件的确切大小,单位 
                charset utf-8,gdk;			//默认中文目录乱码,解决乱码。
                autoindex_localtime on;		//显示的文件时间为文件服务器时间
                
        }
}

[root@nginx_web1 ~]# nginx -t 
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx_web1 ~]# systemctl restart nginx

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43357497/article/details/113763958