Home > Operation and Maintenance > Nginx > How does Nginx support logical operations and uppercase and lowercase letter conversion when writing configuration?

How does Nginx support logical operations and uppercase and lowercase letter conversion when writing configuration?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-14 22:10:04
forward
1101 people have browsed it

Logical operations
nginx configuration does not support the logical AND && logical OR || operation of if conditions, and does not support the nested syntax of if, otherwise the following error will be reported: nginx: [emerg] invalid condition.
We can use variables to achieve this indirectly.
Statement to be implemented:

if ($arg_unitid = 42012 && $uri ~/thumb/){
 echo "www.jb51.net";
}
Copy after login

If configured in this way, nginx: [emerg] invalid condition error will be reported.
It can be implemented like this, as shown below:

set $flag 0;
if ($uri ~ ^/thumb/[0-9]+_160.jpg$){
 set $flag "${flag}1";
}
if ($arg_unitid = 42012){
 set $flag "${flag}1";
}
if ($flag = "011"){
 echo "www.jb51.net";
}
Copy after login

nginx implements uppercase and lowercase letter conversion (ngx_http_lower_upper_case module)
Various programs or scripts have implemented uppercase and lowercase letter conversion Today we will talk about the conversion function of ngx_http_lower_upper_case. The function is very simple. As for the environment in which it can be used, you can decide according to your own situation. One more module and one solution. This module converts strings to uppercase and lowercase and then assigns them to variables. As the saying goes, "existence is reasonable." There is always a reason for the existence of software.
1. Install nginx module

--add-module=path/to/circle_gif/directory
Copy after login

The specific method will not be described. You can refer to the operation and maintenance survival time
2.upper/lower command
upper
Syntax: upper $var string
Configuration section: location
Small to uppercase
lower
Syntax: lower $var string
Configuration section: location
uppercase to lowercase
3. nginx configuration

location /ttlsa_upper_lower {
upper $var1 "hello,jb51.net";
lower $var2 "hello,jb51.net";
echo $var1;
echo $var2;
}
Copy after login

4. Test

# curl http://test.jb51.net/ttlsa_upper_lower/
Copy after login
 hello,jb51.net
 hello,jb51.net
Copy after login

The above is the detailed content of How does Nginx support logical operations and uppercase and lowercase letter conversion when writing configuration?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Error restarting nginx
From 1970-01-01 08:00:00
0
0
0
server - Nginx configuration webapp problem
From 1970-01-01 08:00:00
0
0
0
Nginx default.conf problem
From 1970-01-01 08:00:00
0
0
0
centos7 - NGINX exception occurs
From 1970-01-01 08:00:00
0
0
0
nginx load balancing
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template