目录参数问题

Thu Jun 27, 2024

200 Words|Read in about 1 Min
Tags: Devops  

在一个前端发布一个vue静态项目时候,遇见一个目录参数301的问题。记录一下过程

故障现象

访问 https://www.sklinux.com/abcd?key=12345 会出现两次请求,第一次301 然后再是https://www.sklinux.com/abcd/?key=12345 200状态 前端研发人员反馈是nginx配置存在问题。

问题分析

排查nginx配置和测试

#nginx配置非常简单
server {
	listen 80 ;
	root /data/wwwroot/;
	autoindex on;
	server_name www.sklinux.com;
	index index.html /index.html;
}

进入root目录,发现有文件夹abcd ,文件夹下有index.html 进行测试

curl -I http://127.0.0.1/abcd\?abc\=aadf
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Thu, 27 Jun 2024 00:59:46 GMT
Content-Type: text/html
Content-Length: 178
Location: http://127.0.0.1/abcd/?abc=aadf
Connection: keep-alive

带上目录/后访问测试,一次性200,不再301再200

curl -I http://10.99.1.251/sk/\?abc\=aadf
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Thu, 27 Jun 2024 01:15:24 GMT
Content-Type: text/html
Content-Length: 4
Last-Modified: Thu, 27 Jun 2024 00:33:03 GMT
Connection: keep-alive
ETag: "667cb33f-4"
Accept-Ranges: bytes
curl -I http://10.99.1.251/sk/\?abc\=aadf/index.html
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Thu, 27 Jun 2024 01:21:39 GMT
Content-Type: text/html
Content-Length: 4
Last-Modified: Thu, 27 Jun 2024 00:33:03 GMT
Connection: keep-alive
ETag: "667cb33f-4"
Accept-Ranges: bytes

nginx

解决办法

1.目录后面加上/
2.参数最后带上缺省页面index.html或者自定义页面比如par.html

curl http://www.sklinux.com/dir/?year=2024/year.html
#or
curl http://www.sklinux.com/dir?year=2024/year.html
or
index year.html
curl http://www.sklinux.com/dir/?year=2024

问题总结

1.前端研发人员对静态url规划和前端业务路径设计不规范,对前端动态资源没做好规划。
2.交付和测试不到位

See Also

Thu Jun 27, 2024

200 Words|Read in about 1 Min
Tags: Devops