Nginx the method of supporting logical operation and uppercase and lowercase letters conversion when writing a configuration _nginx

Source: Internet
Author: User
Tags lowercase

Logical operations
the logic and && logic of the IF condition is not supported in the Nginx configuration or | | Operation, and the nested syntax for if is not supported, the following error is reported: Nginx: [Emerg] Invalid condition.
We can do this indirectly by means of variables.
The statement to implement:

if ($arg _unitid = 42012 && $uri ~/thumb/) {
 echo "www.jb51.net";
}

If you configure this, you will report nginx: [Emerg] Invalid condition error.
This can be done as follows:

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 to convert uppercase and lowercase letters (ngx_http_lower_upper_case modules)
a variety of programs or scripts have the ability to achieve the conversion of uppercase and lowercase letters, today, Ngx_http_lower_upper_case, the function is very simple, As for what can be used in the environment you can according to their own situation. One more module, one more solution. This module converts a string to a case and then assigns it to a variable. In the phrase "existence is reasonable", the existence of software always has its own truth.
1. Install Nginx module

--add-module=path/to/circle_gif/directory

The specific method is no longer described, you can refer to the operation of survival time < How to install Nginx third Party module >
2.upper/lower directives
Upper
Syntax: Upper $var string
Configuration segment: Location
Small capitalization
Lower
Syntax: Lower $var string
Configuration segment: Location
Uppercase to lowercase
3. Nginx Configuration

Location/ttlsa_upper_lower {
upper $var 1 "hello,jb51.net";
Lower $var 2 "hello,jb51.net";
echo $var 1;
echo $var 2;
}

4. Test

# Curl http://test.jb51.net/ttlsa_upper_lower/
 Hello,jb51.net
 hello,jb51.net

Nginx Module Address: https://github.com/replay/ngx_http_lower_upper_case/archive/master.zip
Ngx_http_lower_upper_case Address: Https://github.com/replay/ngx_http_lower_upper_case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.