Nginx decodes the UTF8 encoded URL into a \x 16 binary format resulting in an inability to match the static file's problem handling

Source: Internet
Author: User

For example request /touch/article/ Beijing /full.html, arrive nginx after become //touch/ article/%e5%8c%97%e4%ba%ac/full.html,

Nginx static file configuration:

Location ~* ^/touch/article/.*\.html$ {

expires-1;

Root/home/htmlfile;

CharSet UTF-8;

if (!-f $request _filename) {

Proxy_pass http://client.api.com;

}

}

The actual requested address is /home/htmlfile/touch/article/\xe5\x8c\x97\xe4\xba\xac/full.html, and the URL is decoded, but this binary format does not match the static directory, the workaround:


Location ~* ^/touch/article/.*\.html$ {

CharSet Utf-8;

Alias/home/htmlfile$request_uri;

# charset Utf-8;

if (!-f $request _filename) {

Proxy_pass http://client.api.com;

}

}

Use the alias command and $request _uri variable to point to the correct static file.

Note:1) $ Request_uri # contains the original URI of the request parameter

$uri # The current URI without the request parameter , which is the converted address

$request _filename # The file path of the current request, generated by the root or alias instruction and URI request , i.e. Root

A local file path that is actually directed after a series of optimizations, etc.

2) root and alias difference

nginx There are two ways to specify a file path root and Span style= "font-family: ' Times New Roman ';" >alias root Span style= "font-family: ' The song Body '; > and alias The main difference is nginx How to interpret Span style= "font-family: ' Times New Roman ';" >location behind uri


syntax: root  path
root html
configuration segment: server Span style= "font-family: ' The song Body '; >, location , Span style= "font-family: ' Times New Roman ';" >if

[Alias]
Syntax:alias Path
Configuration segment: Location

Instance:

Location ~ ^/weblogs/{

root/data/weblogs/www.ttlsa.com;

AutoIndex on;

auth_basic "Restricted";

auth_basic_user_file passwd/weblogs;

}

if the URI of a request is /weblogs/httplogs/www.ttlsa.com-access.log ,theweb The server will return to the /data/weblogs/www.ttlsa.com/weblogs/httplogs/www.ttlsa.com-access.log the file.
[Info]root is mapped according to the full URI request, which is /path/uri. [/info]
Therefore, the previous request map is Path/weblogs/httplogs/www.ttlsa.com-access.log.

Location ^~/binapp/{

limit_conn limit 4;

limit_rate 200k;

internal;

alias/data/statics/bin/apps/;

}

aliasThe path that is configured behind the location is discarded, and the directory that is currently matched to is pointed to the specified directory. If the URI of a request is /binapp/a.ttlsa.com/favicon ,theWeb Server will return to the server /DATA/STATICS/BIN/APPS/A.TTLSA.COM/FAVICON.JGP the file.
[Warning]1. Use alias must be added after the directory name "/" .
2. Alias can specify any name.
3. Alias when using a regular match, you must capture the content to match and use it at the specified content.
4. Alias can only be located in the location block.

This article from "Quiet Zhiyuan" blog, declined reprint!

Nginx decodes the UTF8 encoded URL into a \x 16 binary format resulting in an inability to match the static file's problem handling

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.