网站死链存在的问题,电子商务网站建设考题与答案,百度热搜风云榜,平凉网站开发location 的斜杠问题比较好理解#xff0c;不带斜杠的是模糊匹配。例如#xff1a;
location /doc
可以匹配 /doc/index.html#xff0c;也可以匹配 /docs/index.html。
location /doc/ 强烈建议使用这种
只能匹配 /doc/index.html#xff0c;不能匹配 /docs/index…location 的斜杠问题比较好理解不带斜杠的是模糊匹配。例如
location /doc
可以匹配 /doc/index.html也可以匹配 /docs/index.html。
location /doc/ 强烈建议使用这种
只能匹配 /doc/index.html不能匹配 /docs/index.html。 对于 proxy_pass 的斜杠问题得结合 location 来讲。 1proxy_pass 不带URL方式 这种 IP、端口后面没有 /是不带 URI 的方式nginx 会保留 location 中的路径。所以访问 http://127.0.0.1/docs/实际上访问的是 http://127.0.0.1:8080/docs/。 访问 http://127.0.0.1/docs/ ---------------------------- 实际访问 http://127.0.0.1:8080/docs/ location /docs/ {proxy_pass http://127.0.0.1:8080;
} location /jenkins/ {proxy_set_header host $host;proxy_pass http://192.168.11.128:8080;}tomcat日志
192.168.11.128 - - [04/Jun/2023:07:50:59 0800] GET /jenkins/index.html HTTP/1.0 404 648 2proxy_pass 带 URI 的方式 这种 IP、端口后面有 /是带 URI 的方式nginx 将会使用别名的方式来对 URL 进行替换。所以访问 http://127.0.0.1/docs/实际上访问的是 http://127.0.0.1:8080//docs/ 替换成了 /。 访问 http://127.0.0.1/docs/ ------------- 实际访问 http://127.0.0.1:8080/ location /docs/ {proxy_pass http://127.0.0.1:8080/;
} location /article/ {proxy_set_header host $host;proxy_pass http://192.168.11.128:8080/;} 后端tomcat日志
192.168.11.128 - - [04/Jun/2023:08:08:56 0800] GET /index.html HTTP/1.0 404 648 对带 URI 的方式进行扩展
location /article/ {proxy_pass http://127.0.0.1:8080/docs/;
}
这种同样 IP、端口后面有 /也是带 URI 的方式。所以访问 http://127.0.0.1/article/实际上访问的是 http://127.0.0.1:8080/docs//article/ 替换成了 /docs/。 举例如下 location /article/ {proxy_set_header host $host;proxy_pass http://192.168.11.128:8080/docs/;} 192.168.11.128 - - [04/Jun/2023:08:00:26 0800] GET /docs/index.html HTTP/1.0 404 648 经常出错的也正是这种带 URI 方式的写法 例如
location /article/ {proxy_pass http://127.0.0.1:8080/docs;
}
当访问 http://127.0.0.1/article/index.html 的时候本意是想访问 http://127.0.0.1:8080/docs/index.html。但是/article/ 替换成了 /docs所以实际访问的是 http://127.0.0.1:8080/docsindex.html。