Home > Article > Operation and Maintenance > How does Nginx support logical operations and uppercase and lowercase letter conversion when writing configuration?
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"; }
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"; }
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
The specific method will not be described. You can refer to the operation and maintenance survival time f71ae83da0fc415886c8ddbe1ccefd2f
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; }
4. Test
# curl http://test.jb51.net/ttlsa_upper_lower/
hello,jb51.net hello,jb51.net
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!