注意:路径中 所有// nginx已/处理 , root和alias的区别请另百度一下
第一种 error_page 404 /开头,正常访问localhost:8080:work-order ,404访问localhost:8080:work-order/home
root
location ^~ /work-order/ {
root basePath/test/;
index index.html index.htm;
error_page 404 /work-order/index.html;
}
status 200: basePath/test//work-order//index.html
status 404: basePath/test//work-order/index.html /开头代表从basePath后开始替换
location ^~ /work-order/ {
root basePath/test/;
index index.html index.htm;
error_page 404 /wen/index.html;
}
status 200: basePath/test//work-order//index.html
status 404: basePath//wen/index.html /开头代表从basePath后开始替换 注:此时访问的是localhost:8080:wen 匹配不到/work-order了
alias
location ^~ /work-order {
alias basePath/test/work/;
index index.html index.htm;
error_page 404 /work-order/index.html;
}
status 200: basePath/test//work//index.html
status 404: basePath/test//work/index.html /work-order/index.html; /开头代表从basePath后开始替换
location ^~ /work-order {
alias basePath/test/work/;
index index.html index.htm;
error_page 404 /wen/index.html;
}
status 200: basePath/test//work//index.html
status 404: basePath//wen/index.html /开头代表从basePath后开始替换 注:此时访问的是localhost:8080:wen 匹配不到/work-order了
第二error_page 404 没有 /开头,访问localhost:8080:work-order,404访问localhost:8080:work-order/home
root
location ^~ /work-order/ {
root basePath/test/;
index index.html index.htm;
error_page 404 work-order/index.html;
}
status 200: basePath/test//work-order//index.html
status 404: basePath/test//work-order/work-order/work-order/work-order/index.html 没有/开头表示相对路径 因为一直404所以/work-order/work-work-order/wen
location ^~ /work-order/ {
root basePath/test/;
index index.html index.htm;
error_page 404 wen/index.html;
}
status 200: basePath/test//work-order//index.html
status 404: basePath/test///work-order/wen/wen/wen/index.html 没有/开头表示相对路径 ,因为一直404所以/wen/wen/wen
alias
location ^~ /work-order {
alias basePath/test/work/;
index index.html index.htm;
error_page 404 work-order/index.html
}
status 200: basePath/test//work//index.html
status 404: basePath/test//work/work-order/work-order/work-order/index.html; 没有/开头表示相对路径,因为一直404所以/work-order/work-work-order/wen
location ^~ /work-order {
alias basePath/test/work/;
index index.html index.htm;
error_page 404 wen/index.html;
}
status 200: basePath/test//work//index.html
status 404: basePath/test//work//wen/wen/wen/wen/index.html /开头代表从basePath后开始替换 因为一直404所以/wen/wen/wen