Centos7.9源码编译nginx-1.22.1+Nginx-Fancyindex模块美化浏览目录 爱极客 2025-06-20 2025-06-20 Centos7.9源码编译nginx-1.22.1+Nginx-Fancyindex模块美化浏览目录
1、安装Nginx所需要的依赖 # yum install -y gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel
2、执行配置: 添加http和https模块和ngx-fancyindex模块 --prefix为指定安装路径,不指定默认安装到/usr/local/nginx目录 # ./configure --prefix=/usr/ local/nginx --with -http_stub_status_module --with -http_ssl_module --add-module =ngx-fancyindex-0.5 .2
3、对Nginx编译和安装
:::tip{title=”提示”} 看到如下信息,说明编译安装成功:
test -f '/usr/local/nginx/conf/scgi_params' \ || cp conf/scgi_params '/usr/local/nginx/conf' cp conf/scgi_params \ '/usr/local/nginx/conf/scgi_params.default' test -f '/usr/local/nginx/conf/nginx.conf' \ || cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf' cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default' test -d '/usr/local/nginx/logs' \ || mkdir -p '/usr/local/nginx/logs' test -d '/usr/local/nginx/logs' \ || mkdir -p '/usr/local/nginx/logs' test -d '/usr/local/nginx/html' \ || cp -R html '/usr/local/nginx' test -d '/usr/local/nginx/logs' \ || mkdir -p '/usr/local/nginx/logs' make[1]: Leaving directory `/acdata/dba_tools/nginx_source/nginx-1.22.1'
:::
4、修改Nginx配置和打包以便后续解压直接使用,省去打包编译。 Fancy Index 配置
location /download { include /usr/local/nginx/html/Nginx-Fancyindex-Theme/fancyindex.conf; root /home/map/www/; autoindex on; autoindex_format html; autoindex_exact_size off; autoindex_localtime on; charset utf-8,gbk; }
4.1、 编辑nginx.conf配置文件: [root@wtj1vpdbmgnt01 conf] worker_processes 3; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location /download{ alias /acdata/dba_tools/shell/check_mysql_report_news/inspection_data_report; fancyindex on; fancyindex_exact_size off; autoindex on; autoindex_format html; autoindex_exact_size off; autoindex_localtime on; charset utf-8,gbk; if ($request_filename ~* ^.*?\.(html|doc|pdf|zip|docx|txt|conf|gz|xz|rar|sql)$) { add_header Content-Disposition attachment; add_header Content-Type application/octet-stream; } auth_basic "开源服务-数据库巡检报告访问验证" ; auth_basic_user_file /etc/nginx/passwd; } location /report{ alias /acdata/dba_tools/shell/check_mysql_report_news/inspection_data_report; fancyindex on; fancyindex_exact_size off; autoindex on; autoindex_format html; autoindex_exact_size off; autoindex_localtime on; charset utf-8,gbk; auth_basic "开源服务-数据库巡检报告访问验证" ; auth_basic_user_file /etc/nginx/passwd; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
4.2、 编辑nginx.service服务文件: [root@wtj1vpdbmgnt01 nginx-1.22.1] [Unit] Description= Nginx-1.22.1 After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
4.3、打压缩包,方便后续重装直接使用,省去编译和配置等工作,直接解压使用。 # 进入到/usr/local目录 # cd /usr/local/ # 执行打包命令 # tar -czvf nginx-1.22 .1 -build_finished.tar .gz nginx
4.4、验证nginx服务是否可以正常启动 [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin]
4.5 配置Nginx服务管理和开机启动 [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin] [root@localhost sbin]