操做系统:CentOS release 6.10html
Web中间件:nginx/1.14.0nginx
Nginx是一款轻量级的Web 服务器。其特色是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。git
任务背景:Nginx Web 服务器自带的目录浏览功能看起来并不美观,在这里使用ngx-fancyindex插件来美化目录浏览功能。github
即配置Nginx索引(目录浏览),美化索引页面。web
实战任务:下载ngx-fancyindex插件并配置服务器
要求:并发
1.已经安装好nginx的环境下安装配置ngx-fancyindex插件;app
2.nginx同插件一同安装配置。ide
1、已经安装好nginx的环境下安装配置ngx-fancyindex插件;网站
操做步骤:
1.下载插件
https://github.com/aperezdc/ngx-fancyindex/archive/master.zip
https://github.com/aperezdc/ngx-fancyindex/releases #选择相关版本下载
2.解压缩
[root@sky9890 src]# unzip ngx-fancyindex-master.zip
3.编辑及配置
[root@sky9890 nginx-1.14.0]#
./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_image_filter_module \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--add-module=../ngx-fancyindex-master #添加第三方插件,指定解压的目录
[root@sky9890 nginx-1.14.0]#make
[root@sky9890 nginx-1.14.0]killall nginx
[root@sky9890 nginx-1.14.0]# cp /objs/nginx /usr/local/nginx/sbin/ #复制从新编译的nginx文件到nginx原来安装目录下
[root@sky9890 nginx-1.14.0]nginx
[root@sky9890 conf]# vi nginx.conf
......
location /{
root /usr/local/nginx/html/
fancyindex on; #开启索引
fancyindex_exact_size off; #显示文件大小
fancyindex_localtime on; #使用本地时间
fancyindex_footer footer.html; #把当前路径下的footer.html内容做为底部
fancyindex_header header.html; #把当前路径下的header.html内容做为顶部
fancyindex_ignore footer.html header.html;
}
运行效果图以下:
2、未安装好nginx的环境下安装配置ngx-fancyindex插件;
[root@sky9890 nginx-1.14.0]#
./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_image_filter_module \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--add-module=../ngx-fancyindex-master #添加第三方插件,指定解压的目录
[root@sky9890 nginx-1.14.0]#make
[root@sky9890 nginx-1.14.0]#make install
[root@sky9890 conf]# vi nginx.conf #配置 nginx便可
......
location /{
root /usr/local/nginx/html/
fancyindex on; #开启索引
fancyindex_exact_size off; #显示文件大小
fancyindex_localtime on; #使用本地时间
fancyindex_footer footer.html; #把当前路径下的footer.html内容做为底部
fancyindex_header header.html; #把当前路径下的header.html内容做为顶部
fancyindex_ignore footer.html header.html;
}
实战经验:
常见错误1:
nginx: [emerg] getpwnam("nginx") failed in /usr/local/nginx/conf/nginx.conf:1
#useradd nginx #添加nginx用户
#vi nginx.conf #配置nginx用户
常见错误2:
[root@sky9890 conf]# nginx
nginx: [emerg] open() "/application/nginx/logs/www.access.log" failed (2: No such file or directory) #没有此路径
access_log /usr/local/nginx/logs/www.access.log; #修改本地路径
error_log /usr/local/nginx/logs/www.error.log; #修改本地路径
常见错误3:
[root@sky9890 conf]# nginx -s reload
nginx: [emerg] unknown directive "fancyindex" in /usr/local/nginx/conf/nginx.conf:61 #没有下载配置fancyindex插件