Specific use of the autoindex module in the Nginx Http module series

Specific use of the autoindex module in the Nginx Http module series

The main function of the brower module is to determine whether the browser is new or old based on the value of "User-Agent" in the http request header and the browser's characteristic characters, and generate corresponding variables for use in subsequent request processing logic.

1. Introduction

The ngx_http_browser_module module generates variables by judging the value of the "User-Agent" request header for subsequent request logic processing.

2. List of built-in variables

$modern_browser
If the browser is identified as a modern browser, it is equal to the value set by the modern_browser_value directive;

$ancient_browser
If the browser is identified as an ancient browser, it is equal to the value set by the Ancient_browser_value directive;

$msie
If the browser is identified as MSIE, regardless of version, it is equal to 1;

3. Configuration Example

Identification logic configuration of modern browsers:

modern_browser_value "modern.";

# modern_brower specifies which browser and its version are considered modern browsers. The configuration format will be described later in modern_browser msie 5.5;
modern_browser gecko 1.0.0;
modern_browser opera 9.0;
modern_browser safari 413;
modern_browser konqueror 3.0;

 
When the browser is judged to be a modern browser, the modern_browser variable is equal to "modern.", which is the variable configured by modern_browser_value.
index index.${modern_browser}html index.html;

Compatibility judgment of old browsers:

modern_browser msie 5.0;
modern_browser gecko 0.9.1;
modern_browser opera 8.0;
modern_browser safari 413;
modern_browser konqueror 3.0;

modern_browser unlisted;

# ancient_browser configures which substrings are identified as ancient browsers ancient_browser Links Lynx netscape4;

# When the browser is identified as an ancient browser, ancient_browser is 1; here you can do compatibility processing or give the user a direct prompt to update or replace the modern browser;

if ($ancient_browser) {
  rewrite ^ /ancient.html;
}

4. Configuration format

Syntax: ancient_browser string ...;
Default: —
Context: http, server, location

When configuring the "User-Agent" header with a seed string, it is judged as an old browser. The special substring "netscape4" is equivalent to the regular expression: ^Mozilla/[1-4]

Syntax: ancient_browser_value string;
Default:  
ancient_browser_value 1;
Context: http, server, location

When an ancient browser is identified, the value of the $ancient_browser variable defaults to 1;

Syntax: modern_browser browser version;
modern_browser unlisted;
Default: —
Context: http, server, location

When configuring which browser and which version to use, it is determined to be a modern browser. The browser value is: msie, gecko, opera, safari, konqueror. The version definition format is X, XX, XXX, or XXXX. The maximum value of each format is: 4000, 4000.99, 4000.99.99, and 4000.99.99.99.

unlisted is a special string. When a browser does not appear in the matching range of modern_browser and ancient_browser, it is regarded as a modern browser. Otherwise it is considered an ancient browser. If the "User-Agent" header is not provided in the request header, it is considered not to appear in the matching list.

Syntax: modern_browser_value string;
Default:  
modern_browser_value 1;
Context: http, server, location

When a modern browser is identified, the value of the $modern_browser variable defaults to 1;

4. Summary

ngx_http_browser_module provides a browser compatibility judgment mechanism, which makes us more elegant and efficient when dealing with compatibility between old and new browsers. You can use it more in actual needs, extract the browser version from the business logic, and make the business more like a business without considering other things.

This is the end of this article about the specific use of the autoindex module in the Nginx Http module series. For more relevant Nginx autoindex module content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of the data storage structure of the nginx http module
  • Common instructions for nginx HTTP module configuration

<<:  Nofollow makes the links in comments and messages really work

>>:  CSS removes the background color of elements generated when they are clicked on the mobile terminal (recommended)

Recommend

Detailed implementation plan of Vue front-end exporting Excel files

Table of contents 1. Technology Selection 2. Tech...

A MySQL migration plan and practical record of pitfalls

Table of contents background Solution 1: Back up ...

Steps for installing MySQL 8.0.16 on Windows and solutions to errors

1. Introduction: I think the changes after mysql8...

How to manually deploy war packages through tomcat9 on windows and linux

The results are different in Windows and Linux en...

About the correct way to convert time in js when importing excel

Table of contents 1. Basics 2. Problem Descriptio...

MySQL trigger usage scenarios and method examples

trigger: Trigger usage scenarios and correspondin...

Analysis of Mysql transaction characteristics and level principles

1. What is a transaction? A database transaction ...

Ideas for creating wave effects with CSS

Previously, I introduced several ways to achieve ...

Sample code using scss in uni-app

Pitfalls encountered I spent the whole afternoon ...

Docker builds cluster MongoDB implementation steps

Preface Due to the needs of the company's bus...

The phenomenon of margin-top collapse and the specific solution

What is margin-top collapse Margin-top collapse i...

Detailed explanation of MySQL transaction processing usage and example code

MySQL transaction support is not bound to the MyS...