apache默认是开启目录浏览功能的,nginx须要配置下才能实现。html
编译安装nginx
nginx
在官网下载最新版本的nginx,编译安装apache
[root@nginx ~]# yum -y install pcre pcre-devel服务器
[root@nginx ~]# wget http://nginx.org/download/nginx-1.9.9.tar.gz ide
[root@nginx ~]# tar xf nginx-1.9.9.tar.gz
spa
[root@nginx ~]# ./configure --prefix=/usr/local/nginxserver
[root@nginx ~]# make && make installhtm
2.打开配置文件,在server段添加代码blog
[root@nginx ~]# vi /usr/local/nginx/conf/nginx.confutf-8
server {
listen 80;
server_name localhost;
root /var/www/html/;
charset utf-8;
location / {
autoindex on; #开启功能
autoindex_exact_size off; #off显示文件大小,单位是kB、MB、GB;on显示bytes
autoindex_localtime on; #off显示的文件时间为GMT时间;on显示是服务器时间;
index index.html index.htm;
}
}
3.查看配置文件
[root@nginx ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
4.启动nginx服务
[root@nginx ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
5.建立浏览目录
[root@nginx ~]# mkdir /var/www/html/nginx