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