Example
Mobile browser?
The code is as follows: |
Copy code |
Location = /{ Root/var/www/path; If ($ http_user_agent ~ * "Nokia") {rewrite./index.html break ;} If ($ http_user_agent ~ * "Mobile") {rewrite./index.html break ;} If ($ http_user_agent ~ * "SAMSUNG") {rewrite./index.html break ;}} If ($ http_user_agent ~ * "SonyEricsson") {rewrite./index.html break ;} If ($ http_user_agent ~ * "MOT") {rewrite./index.html break ;}} If ($ http_user_agent ~ * "BlackBerry") {rewrite./index.html break ;} If ($ http_user_agent ~ * "LG") {rewrite./index.html break ;}} If ($ http_user_agent ~ * "HTC") {rewrite./index.html break ;} If ($ http_user_agent ~ * "J2") {rewrite./index.html break ;} If ($ http_user_agent ~ * "Opera Mini") {rewrite./index.html break ;}} Index index.html; } |
Or
The code is as follows: |
Copy code |
1. set $ ismob 0; 2. if ($ http_user_agent ~ "^ ((. * MIDP. *) | (. * WAP. *) | (. * UP. browser. *) | (. * Smartphone. *) | (. * Obigo. *) | (. * Mobile. *) | (. * AU. browser. *) | (. * wxd. mms. *) | (. * WxdB. browser. *) | (. * CLDC. *) | (. * UP. link. *) | (. * KM. browser. *) | (. * UCWEB. *) | (. * SEMC-Browser. *) | (. * Mini. *) | (. * Symbian. *) | (. * Palm. *) | (. * Nokia. *) | (. * Panasonic. *) | (. * MOT -. *) | (. * SonyEricsson. *) | (. * NEC -. *) | (. * Alcatel. *) | (. * Ericsson. *) | (. * BENQ. *) | (. * BenQ. *) | (. * Amoisonic. *) | (. * Amoi -. *) | (. * Capitel. *) | (. * PHILIPS. *) | (. * SAMSUNG. *) | (. * Lenovo. *) | (. * Mitsu. *) | (. * Motorola. *) | (. * SHARP. *) | (. * WAPPER. *) | (. * LG -. *) | (. * LG /. *) | (. * EG900. *) | (. * CECT. *) | (. * Compal. *) | (. * kejian. *) | (. * Bird. *) | (. * BIRD. *) | (. * G900/v1.0.*) | (. * Arima. *) | (. * CTL. *) | (. * TDG. *) | (. * Daxian. *) | (. * DAXIAN. *) | (. * DBTEL. *) | (. * Eastcom. *) | (. * EASTCOM. *) | (. * PANTECH. *) | (. * Dopod. *) | (. * Haier. *) | (. * HAIER. *) | (. * KONKA. *) | (. * KEJIAN. *) | (. * LENOVO. *) | (. * Soutec. *) | (. * SOUTEC. *) | (. * SAGEM. *) | (. * SEC -. *) | (. * SED -. *) | (. * EMOL -. *) | (. * INNO55. *) | (. * ZTE. *) | (. * iPhone. *) | (. * Android. *) | (. * Windows CE. *) | (Wget. *) | (java. *) | (curl. *) | (Opera. *) $ ") 3 .{ 4. set $ ismob 1; 5. proxy_pass http://www.111cn.net; 6 .} 7. if ($ http_user_agent ~ ^ $) 8 .{ 9. set $ ismob 1; 10. proxy_pass http://www.111cn.net; 11 .} 12. if ($ ismob = 0) 13 .{ 14. rewrite "^. * $" http://www.111cn.net/permanent; 15 .} |
Example
Filter YisouSpider by User Agent
Find the root directory configuration area, add the User Agent filter and judgment statement, and find that "YisouSpider" directly returns 403
Note 1: If you need to add multiple filters, do this ($ http_user_agent ~ * "Spider1 | Spider2 | Spider3 | Spider4"), separated by |
Note 2: If you are using a sub-directory blog, you need to find a section like "location/blog/" to modify it.
The code is as follows: |
Copy code |
Location /{ Other configurations If ($ http_user_agent ~ * "YisouSpider "){ Return 403; } } |
After wq is configured, reload nginx and run the following command to perform self-test. Change the address. I can't do it without installing curl. I can install apt or yum as an artifact.
The code is as follows: |
Copy code |
Curl-I-A "YisouSpider" www.111cn.net |
If 403 is returned, the configuration is successful.