Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.7k views
in Technique[技术] by (71.8m points)

请求能正确发到服务器嘛?

假设服务器公网地址是 122.33.21.3
服务器部署了一个web服务在80端口
在服务器上有一个后端服务在7001端口

当用户访问122.33.21.3:80的时候
前端的请求base是localhost:7001

这样写的话 用户在本地打开 请求是用户电脑7001端口还是远程服务器的7001端口?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

请求的是你本地的,即用户电脑的7001端口。
你要想访问服务器的7001的话,调接口的时候不加localhost,比如调http://122.33.21.3/api,你代码里就写/api,不要写http://localhost/api


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...