Nginx服务器的nginx-http-footer-filter模块怎么配置
1. nginx-http-footer-filter到底是做什么的?
说白了,就是在请求的页面底部插入你要插入的代码。
2. 我们能用nginx-http-footer-filter来做什么?
1、统一追加js代码用于统计(我是这么想的)
2、底部追加响应这个请求的realsver(后端真实服务器)信息,便于系统管理员排查故障.
3、你管理着数量庞大的虚拟主机,在所有web后面追加你的广告代码,黑链什么的(很无耻)
4、举一反三吧,自己想想能用来做什么吧.
淘宝用它来做什么?
打开淘宝首页,查看他源代码,拖到最下面,内容如下:
<!--city: fuzhou--> <!--province: unknown--> <!--hostname: --> <!--hostname: home1.cn199-->
我们可以很清晰的看到,这边有省和地区还有主机名,也就是淘宝真实服务器的主机名,处理我这个请求的主机名为home1.cn199, city取到了fuzhou,provinece省份没取到,估计是它geo的问题
或者随便打开一个商品页面, 查看源代码,如下:
</html> <script type="text/javascript">tshop.initfoot({});</script>
可以看到他这边给这页面追加了一个js代码,淘宝开发这个模块的用意想必大家都明白了,集思广益,或许大家还有更好的用处.
3. 怎么安装nginx-http-footer-filter
3.1 下载地址:
https://github.com/alibaba/nginx-http-footer-filter/tree/1.2.2
3.2 安装nginx-footer模块
之前已经安装过nginx,所以我选择覆盖nginx文件。
# cd /usr/local/src/ # wget https://codeload.github.com/alibaba/nginx-http-footer-filter/zip/1.2.2 # unzip 1.2.2 # http://nginx.org/download/nginx-1.4.1.tar.gz # tar -xzvf nginx-1.4.1.tar.gz # cd nginx-1.4.1 # ./configure --prefix=/usr/local/nginx-1.4.1 \ --with-http_stub_status_module --with-http_realip_module \ --add-module=../nginx-http-footer-filter-1.2.2 # make # mv /usr/local/nginx-1.4.1/sbin/nginx /usr/local/nginx-1.4.1/sbin/old_nginx # mv objs/nginx /usr/local/nginx-1.4.1/sbin/ # /usr/local/nginx-1.4.1/sbin/nginx -s stop # /usr/local/nginx-1.4.1/sbin/nginx
3.3 验证模块是否安装成功
# /usr/local/nginx-1.4.1/sbin/nginx -v nginx version: nginx/1.4.1 built by gcc 4.4.7 20120313 (red hat 4.4.7-3) (gcc) tls sni support enabled configure arguments: --prefix=/usr/local/nginx-1.4.1 --with-http_stub_status_module --with-http_realip_module --add-module=../nginx-http-footer-filter-1.2.2
4. 怎么使用nginx-http-footer-filter模块
4.1 配置location
在location中使用footer "你的内容" 即可.看如下配置
server { listen 173.255.219.122:80; server_name test.ttlsa.com; access_log /data/logs/nginx/test.ttlsa.com.access.log main; index index.html index.php index.html; root /data/site/test.ttlsa.com; location / { footer "<!-- $date_gmt -->"; index index.html; } location =/html/2252.css { footer_types text/css; footer "/* host: $server_name - $date_local */"; }
4.2 测试nginx-footer效果
# cat 2252.shtml <html> <head> <title>test</title> </head> <body> this is webpage </body> </html>
访问站点test.ttlsa.com/html/2252.shtml
如图,我们可以看到文件最底部加上了,怎么变成了时间撮了,因为我这边是ssi的语法,如果你不知道什么是ssi,那么请参考文章什么是ssi.
[warning]他仅仅是在文件的最后一行追加,而不是
4.3 再来测试一下css文件
# cat 2242.css # this is css file
如下是访问结果:
# this is css file /* host: test.ttlsa.com - 1376064324 */
看图:
5. 我能写多个footer指令吗?
不行,以下我写了两个footer
location / { footer "12312321321"; footer "<!-- $date_gmt -->"; index index.html; }
如下测试,提示footer指令重复了
# /usr/local/nginx-1.4.1/sbin/nginx -t nginx: [emerg] "footer" directive is duplicate in /usr/local/nginx-1.4.1/conf/vhost/test.ttlsa.com.conf:13 nginx: configuration file /usr/local/nginx-1.4.1/conf/nginx.conf test failed
6. 只能用ssi变量吗?
当然不是,随便你写,可以是ssi指令,也可以是nginx变量,也可以是任何无意义的字符串
如下:
footer "12312321321"; footer "<!--12312321321-->"; footer "<!--$remote_addr-->";
比如我想知道这个页面是哪台web服务器处理的,那么我在底部插入主机名即可.这样,有500错误,我便可以马上定位到具体的服务器了
footer "<!--$hostname-->";
返回结果如下:
7. 服务器返回500,404,403等错误, 是否还会追加内容到底部
会,如果不追加,就无法通过返回的页面得知哪台web出现故障,这明显就不符合作者的初衷了
配置如下:
location / { return 500; footer "<!--$hostname-->"; }
结果如下:
8. 模块指令说明:
footer模块非常简单,就只有两个指令,具体说明如下
footer字符串
默认值:
配置段: http, server, location
这个定义了将什么内容追加到文件内容的底部
footer_types mime类型
默认值: footer_types: text/html
配置段: http, server, location
以上是Nginx服务器的nginx-http-footer-filter模块怎么配置的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

在 Linux 中启动 Nginx 的步骤:检查 Nginx 是否已安装。使用 systemctl start nginx 启动 Nginx 服务。使用 systemctl enable nginx 启用在系统启动时自动启动 Nginx。使用 systemctl status nginx 验证启动是否成功。在 Web 浏览器中访问 http://localhost 查看默认欢迎页面。

启动 Nginx 服务器需要按照不同操作系统采取不同的步骤:Linux/Unix 系统:安装 Nginx 软件包(例如使用 apt-get 或 yum)。使用 systemctl 启动 Nginx 服务(例如 sudo systemctl start nginx)。Windows 系统:下载并安装 Windows 二进制文件。使用 nginx.exe 可执行文件启动 Nginx(例如 nginx.exe -c conf\nginx.conf)。无论使用哪种操作系统,您都可以通过访问服务器 IP

如何在 Windows 中配置 Nginx?安装 Nginx 并创建虚拟主机配置。修改主配置文件并包含虚拟主机配置。启动或重新加载 Nginx。测试配置并查看网站。选择性启用 SSL 并配置 SSL 证书。选择性设置防火墙允许 80 和 443 端口流量。

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

如何解决 Nginx 403 Forbidden 错误?检查文件或目录权限;2. 检查 .htaccess 文件;3. 检查 Nginx 配置文件;4. 重启 Nginx。其他可能原因还包括防火墙规则、SELinux 设置或应用程序问题。

服务器无权访问所请求的资源,导致 nginx 403 错误。解决方法包括:检查文件权限。检查 .htaccess 配置。检查 nginx 配置。配置 SELinux 权限。检查防火墙规则。排除其他原因,如浏览器问题、服务器故障或其他可能的错误。

在 Linux 中,使用以下命令检查 Nginx 是否已启动:systemctl status nginx根据命令输出进行判断:如果显示 "Active: active (running)",则 Nginx 已启动。如果显示 "Active: inactive (dead)",则 Nginx 已停止。

解决 Nginx 跨域问题有两种方法:修改跨域响应头:添加指令以允许跨域请求,指定允许的方法和头,以及设置缓存时间。使用 CORS 模块:启用模块并配置 CORS 规则,允许跨域请求、方法、头和设置缓存时间。
