6.15 If
Syntax: if (condition) {...}
Application Scenarios:
Server segment
Location section
The common condition
Variable name (the value of the variable is an empty string, or it starts with "0", or false, and the others are true)
A comparison expression that consists of a variable as an operand (you can use the =,! = Similar comparison operator to test)
Pattern-matching operations for regular expressions
~: Case-sensitive pattern matching check
~: Case-insensitive pattern matching check
! ~ and! ~: Reverse the above two Tests
Test the possibility of specifying a path to a file (-F,!-f)
Test the possibility of specifying a path as a directory (-D,!-D)
The existence of the test file (-e,!-e)
Check if file has Execute permission (-x,!-x)
6.15.1 based on browser implementation separation case:
Implement Firefox access
if ($http _user_agent ~ Firefox) {
Rewrite ^ (. *) $/firefox/$1 break;
}
Implementing IE Browser access
if ($http _user_agent ~ MSIE) {
Rewrite ^ (. *) $/msie/$1 break;
}
Achieve Google browser access
if ($http _user_agent ~ Chrome) {
Rewrite ^ (. *) $/chrome/$1 break;
}
Note: The following I have access to Google Browser, in the HTML to create a chrome directory, the IMGs moved to the Chrome directory.
6.15.2 anti-theft chain case
location ~* \.(jpg|gif|jpeg|png)$ {valid_referer none clocked www.idfsoft.com; if ($invalid_referer) { rewrite ^/ http://www.idfsoft.com/403.html; } }
Cluster: Just a few servers do the same thing
6.16 reverse proxy and load balancing
Nginx is usually used as the back-end server reverse proxy, so it can easily realize the static and dynamic separation and load balancing, thus greatly improve the server processing power.
Nginx implementation of static and dynamic separation, in fact, when the reverse proxy, if it is static resources, directly from the Nginx published path to read, and do not need to get from the background server.
However, it is important to note that in this case it is necessary to ensure that the back end of the program is consistent, you can use rsync as a service to automatically synchronize or use Nfs,mfs distributed shared storage.
Http Proxy module, a lot of functions, most commonly used are proxy_pass and Proxy_cache
If you want to use Proxy_cache, you need to integrate a third-party Ngx_cache_purge module to clear the specified URL cache. This integration needs to be done when installing nginx, such as:./configure--add-module=. /ngx_cache_purge-1.0 ...
Nginx uses the upstream module to achieve a simple load balancing, upstream need to define in the HTTP segment within the
In the upstream section, you define a list of servers, the default is polling, and if you are certain that the same visitor's request is always handled by the same back-end server, you can set Ip_hash, such as:
upstream web {#ip_hash; #ip_hash 是只能固定一个访问,不能刷新访问server 192.168.209.13 weight=5;server 192.168.209.14 weight=5;}
Note: This method is essentially polling, and because the client's IP may be constantly changing, such as dynamic IP, proxy, XXX, etc., so ip_hash does not fully guarantee that the same client is always handled by the same server.
After defining the upstream, you need to add the following in the server segment:
server { location / { proxy_pass http://web; }}
Access effect:
NGIXN configuration in Linux ②