您的位置:首页 > 运维架构 > Nginx

Nginx添加第三方模块ngx-fancyindex

2018-12-25 13:03 1946 查看

操作系统:CentOS release 6.10

Web中间件:nginx/1.14.0

     Nginx是一款轻量级的Web 服务器。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、京东、新浪、网易、腾讯、淘宝等。

任务背景:Nginx Web 服务器自带的目录浏览功能看起来并不美观,在这里使用ngx-fancyindex插件来美化目录浏览功能。

即配置Nginx索引(目录浏览),美化索引页面。

实战任务:下载ngx-fancyindex插件并配置

要求:

1.已经安装好nginx的环境下安装配置ngx-fancyindex插件;

2.nginx同插件一同安装配置。

一、已经安装好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;

}

运行效果图如下:

二、未安装好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插件



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  nginx linux ngx-fancyindex