概括:静态文件正在发布/路径/到/根,如果请求不在静态文件夹中,则请求发送@a1位置块。
静态文件;
/路径/到/根/文件夹/folder1,111/index.html
/路径/到/根/文件夹/folder1-111/index.html
配置
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;
}
笔记:web.conf 转到应用程序
静态服务不起作用,因为文件夹名称中有“,”字符
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
静态服务有效,因为文件夹名称没有“,”字符
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
问-1 https://www.example.com/folder/folder1,111为什么这个请求仍然会@a1位置?而文件夹位于 path/to/root 中。那么,如何从静态文件中发布文件名中带有逗号的文件夹?
问-2我如何将 request_uri 发送到@a1如果请求参数包含一些单词?
例子;
字:排序,q,页面
如果请求 uri有任何关于以上内容的留言,请发送至@a1。如果不是,则从静态文件发布到。
答案1
我找到了问题的答案。最新且有效的配置如下。
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; }