51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Nginx和Fancyindex实现索引目录

一、Nginx简介

‌Nginx(发音为 "Engine-X")是一个高性能的Web服务器、反向代理服务器、负载均衡器和HTTP缓存。‌它最初由Igor Sysoev开发,并于2004年发布,迅速成为全球最受欢迎的Web服务器之一。Nginx以其高性能、轻量级和低资源消耗著称,尤其适用于处理大量并发连接。‌

默认的index效果图

二、安装Fancyindex

1、安装Git

[root@localhost ~]# yum -y install git

2、下载Fancyindex模块

[root@localhost ~]# cd /usr/local/

[root@localhost local]# git clone https://gitcode.com/gh_mirrors/ng/ngx-fancyindex.git

3、下载Nginx-Fancyindex-Theme

[root@localhost local]# git clone https://gitcode.com/gh_mirrors/ngin/Nginx-Fancyindex-Theme.git

三、安装Nginx

1、安装依赖包

[root@localhost local]# yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ make wget

2、下载Nginx安装包

[root@localhost local]# wget http://nginx.org/download/nginx-1.26.2.tar.gz

3、解压

[root@localhost local]# tar zxf nginx-1.26.2.tar.gz

创建Nginx用户

[root@localhost local]# useradd -s /sbin/nologin nginx

4、预编译

[root@localhost local]# cd nginx-1.26.2

[root@localhost nginx-1.26.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-stream --with-pcre --with-http_gzip_static_module --with-http_realip_module --add-module=/usr/local/ngx-fancyindex

5、编译及安装

[root@localhost nginx-1.26.2]# make && make install

6、Fancyindex索引配置

修改Nginx配置文件,配置内容如下

[root@localhost nginx-1.26.2]# vim /usr/local/nginx/conf/nginx.conf

    user nginx nginx;
    worker_processes auto;
    pid /usr/local/nginx/logs/nginx.pid;
events {
    use epoll;
    worker_connections 10240;
    multi_accept on;
}
http {
    include mime.types;
    default_type application/octet-stream;
    log_format json escape=json
                '{"访问者IP":"$remote_addr",'
                '"访问时间":"$time_iso8601",'
                '"访问页面":"$uri",'
                '"请求返回时间":"$request_time/S",'
                '"请求方法类型":"$request_method",'
                '"请求状态":"$status",'
                '"请求体大小":"$body_bytes_sent/B",'
                '"访问者搭载的系统配置和软件类型":"$http_user_agent",'
                '"虚拟服务器IP":"$server_addr"}';
    access_log /usr/local/nginx/logs/access.log json;
    error_log /usr/local/nginx/logs/error.log warn;
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 120;
    tcp_nodelay on;
    server_tokens off;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 64k;
    gzip_http_version 1.1;
    gzip_comp_level 4;
    gzip_types text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
    client_max_body_size 512m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 90;
    proxy_send_timeout 90;
    proxy_buffer_size 4k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    large_client_header_buffers 4 4k;
    client_header_buffer_size 4k;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;
    include /usr/local/nginx/conf.d/*.conf;
}

创建引用目录

[root@localhost nginx-1.26.2]# mkdir -p /usr/local/nginx/conf.d

创建Fancyindex配置文件

[root@localhost nginx-1.26.2]# vim /usr/local/nginx/conf.d/fancyindex.conf

server {
    listen 80;
    server_name localhost;
    charset utf-8;
    location / {
    root /usr/local/nginx/html/software/;
    fancyindex on;
    fancyindex_localtime on;
    fancyindex_exact_size off;
    # 有两个主题可以选择,可以选择light或者dark
    fancyindex_header "/Nginx-Fancyindex-Theme/light-Theme/header.html";
    fancyindex_footer "/Nginx-Fancyindex-Theme/light-Theme/footer.html";
    fancyindex_ignore "Nginx-Fancyindex-Theme";
    fancyindex_ignore "Nginx-Fancyindex-Theme";
    }
}

创建存放目录

[root@localhost nginx-1.26.2]# mkdir -p /usr/local/nginx/html/software

[root@localhost nginx-1.26.2]# cp -a /usr/local/Nginx-Fancyindex-Theme /usr/local/nginx/html/software/

创建测试文件

[root@localhost nginx-1.26.2]# cp /usr/local/nginx-1.26.2.tar.gz /usr/local/nginx/html/software/

7、启动Nginx

检测语法

[root@localhost nginx-1.26.2]# /usr/local/nginx/sbin/nginx -t

[root@localhost nginx-1.26.2]# /usr/local/nginx/sbin/nginx

8、访问Nginx

light-Theme主题

dark-Theme主题


继续阅读

历史上的今天

1 月
15

赞(0)
未经允许不得转载:工具盒子 » Nginx和Fancyindex实现索引目录