0

Summary: Static files are publishing in /path/to/root , If the request is not in the static folders, the request sending @a1 location block.

Static files;

/path/to/root/folder/folder1,111/index.html

/path/to/root/folder/folder1-111/index.html

Configuration

location / {
   root /path/to/root;
   error_page 418 = @a1;

if ($request_uri ~ .*.sort.*) { return 418; }

   try_files $request_uri $request_uri/index.html $uri.html @a1;
   add_header X-debug-static-1 "$request_uri" always;
}

location @a1 {
    add_header X-debug-web "$request_uri" always;
    include web.conf;
   }

Note: web.conf going to app

static serving doesn't work, because folder name have "," character

curl -I https://www.example.com/folder/folder1,111

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Thu, 30 Nov 2017 14:56:38 GMT
Content-Type: text/plain; charset=utf-8
Content-Length: 111
Connection: keep-alive
X-DNS-Prefetch-Control: off
X-Frame-Options: DENY
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Location: folder/folder1,111
Vary: Accept, Accept-Encoding
X-debug-web: https://www.example.com/folder/folder1,111

static serving works, because folder name doesn't have "," character

curl -I https://www.example.com/folder/folder1-111

HTTP/1.1 200 OK
Server: nginx
Date: Thu, 30 Nov 2017 15:04:14 GMT
Content-Type: text/html
Content-Length: 306730
Last-Modified: Thu, 30 Nov 2017 15:04:09 GMT
Connection: keep-alive
Vary: Accept-Encoding
ETag: "5a201de9-4ae2a"
X-debug-static-1: /folder/folder1-111
Accept-Ranges: bytes

Q-1 https://www.example.com/folder/folder1,111 Why this request still going to @a1 location? Whereas the folder in path/to/root. So, how can I publish folders with commas in filenames from static files?

Q-2 How can I send request_uri to @a1 if the query_string contains some words?

Example;

words: sort,q,page

If the request_uri have any words from the above, send to @a1. If not, publish to the from static files.

  • Don't use `$request_uri` with `try_files`, use `$uri` instead. The latter is normalised, URL encoded characters are decoded and the query string has been stripped off. See [this link](http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files) – Richard Smith Dec 01 '17 at 12:23
  • Actually I think this isn't about $uri or $request_uri. I did **location ^~ /** and https://www.example.com/folder/folder1,111 works. – Abdullah Ceylan Dec 01 '17 at 14:33
  • BTW, only index.html serving but not index.js with this configuration. https://www.example.com/folder/folder1,111/index.html is works but https://www.example.com/folder/folder1,111/index.js isn't working. Why? – Abdullah Ceylan Dec 01 '17 at 14:35

1 Answers1

0

I have found answers of my questions. Latest and working configuration as below.

    location ^~ / {
    root /path/to/root;    
    error_page 418 = @a1;

    if ($request_uri ~ "(.*)(some|word)(.*)") { return 418; }

        try_files $request_uri $request_uri/index.html $uri.html @a1;   
     add_header X-debug-static-1 "$request_uri" always; }

     location @a1 {
         add_header X-debug-web "$request_uri" always;
         include web.conf;    }