Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure the nginx-http-footer-filter module of Nginx server

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to configure the nginx-http-footer-filter module of Nginx server". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to configure the nginx-http-footer-filter module of the Nginx server.

1. What exactly does nginx-http-footer-filter do?

To put it bluntly, insert the code you want to insert at the bottom of the requested page.

two。 What can we do with nginx-http-footer-filter?

1. Uniformly append js code for statistics (I think so)

2. Append the realsver (back-end real server) information in response to this request at the bottom to facilitate the system administrator to troubleshoot.

3. You manage a large number of virtual hosts, adding your ad code, black chain and so on (shameless) to all web.

4. Draw an example and think about what you can do with it.

What does Taobao do with it?

Open the home page of Taobao, view his source code, and drag it to the bottom, as follows:

We can see very clearly that there are provinces and regions as well as the host name here, that is, the host name of the real server on Taobao. The host name that handles my request is home1.cn199, and the city has failed to get it from the fuzhou,provinece province, which is probably due to its geo problem.

Or open any product page and view the source code, as follows:

Tshop.initfoot ({})

You can see that he added a js code to this page. Taobao must have understood the intention of developing this module, brainstorming, and maybe we have a better use.

3. How to install nginx-http-footer-filter

3.1 download address:

Https://github.com/alibaba/nginx-http-footer-filter/tree/1.2.2

3.2 install the nginx-footer module

Nginx has been installed before, so I chose to overwrite the nginx file.

# 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 verify that the module is installed successfully

# / usr/local/nginx-1.4.1/sbin/nginx-vnginx version: nginx/1.4.1built by gcc 4.4.7 20120313 (red hat 4.4.7-3) (gcc) tls sni support enabledconfigure 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. How to use the nginx-http-footer-filter module

4.1 configure location

Just use footer "your content" in location. Look at the following configuration

Server {listen 173.255.219.122 data/logs/nginx/test.ttlsa.com.access.log main; index index.html index.php index.html; root 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 "; index index.html;} location = / html/2252.css {footer_types text/css Footer "/ * host: $server_name-$date_local * /";}

4.2 Test the effect of nginx-footer

# cat 2252.shtml test this is webpage

Visit the site test.ttlsa.com/html/2252.shtml

As shown in the picture, we can see how the addition at the bottom of the file has become a time summary, because my side is the syntax of ssi, if you do not know what ssi is, then please refer to the article what is ssi.

[warning] he just appends it to the last line of the file, not inside it. You should pay attention to this. [/ warning]

4.3 Let's test the css file again.

# cat 2242.css# this is css file

The results of the interview are as follows:

# this is css file/* host: test.ttlsa.com-1376064324 * /

Look at the picture:

5. Can I write multiple footer instructions?

No, I wrote two footer below.

Location / {footer "12312321321"; footer ""; index index.html;}

The following test indicates that the footer instruction is duplicated

# / usr/local/nginx-1.4.1/sbin/nginx-tnginx: [emerg] "footer" directive is duplicate in/ usr/local/nginx-1.4.1/conf/vhost/test.ttlsa.com.conf:13nginx: configuration file / usr/local/nginx-1.4.1/conf/nginx.conf test failed

6. Can only use the ssi variable?

Of course not. You can write it. It can be a ssi instruction, a nginx variable, or any meaningless string.

As follows:

Footer "12312321321"; footer ""; footer ""

For example, if I want to know which web server handles this page, I can insert the hostname at the bottom. In this way, if there are 500 errors, I can locate the specific server immediately.

Footer ""

The returned result is as follows:

7. The server returned an error such as 500404403. Will the content be appended to the bottom?

Yes, if it is not appended, you will not be able to know which web failed through the returned page, which is obviously not in line with the author's original intention.

The configuration is as follows:

Location / {return 500; footer "";}

The results are as follows:

8. Module instruction description:

The footer module is very simple, with only two instructions, as follows

Footer string

Default value:

Configuration segment: http, server, location

This defines what is appended to the bottom of the file

Footer_types mime Typ

Default value: footer_types: text/html

Configuration segment: http, server, location

At this point, I believe you have a deeper understanding of "how to configure the nginx-http-footer-filter module of the Nginx server". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report