Nginx to determine that access to the file or directory does not exist rewrite

Source: Internet
Author: User

File and directory matching, where:
*-F and!-f to determine if a file exists
*-D and!-d to determine if a directory exists
*-E and!-e to determine if a file or directory exists
*-X and!-x to determine if the file is executable

Example: Determine whether the access to the picture exists, there is no jump to another domain name

   Location ~* ^.+. (jpg|jpeg|gif|css|png|js|ico| thumb) {       root    /data/wwwroot/bbs.xxx.com;       Expires 10d;        if (-e $request _filename) {           ^/data/attachment/forum/(. *) $ http://img.xxx.com/forum/$1 permanent;        }   }

There is a problem here:

Incorrect syntax for overriding rewrite in Nginx [Emerg] unknown directive "if ($host! ="

Nginx syntax detection is particularly strict, if and after the parentheses and variable equals the elements must have spaces, so the correct wording is:
if ' www.0xcafebaby.com ' ) {  ^ (. *) $ http://www.0xcafebaby.com$1 Permanent;   }  
Use a ^ instead of a space to look clearer:
if^ (^ $host ^!=^'www.0xcafebaby.com'^) {
Anyway more dozen space is, so nginx in the Chinese configuration file interpretation can refer to: Nginx configuration file Chinese comments in detail if you want to know more Nginx rewrite configuration, can refer to: Nginx rewrite parameters Daquan

Nginx to determine that access to the file or directory does not exist rewrite

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.