Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部署之后还是请求本地API #5795

Closed
Liqiankun opened this issue Dec 22, 2019 · 10 comments
Closed

部署之后还是请求本地API #5795

Liqiankun opened this issue Dec 22, 2019 · 10 comments

Comments

@Liqiankun
Copy link

💻 示例代码

config文件配置

  proxy: {
    '/api': {
      target: 'https://xcx-img.teamup.group:9000/api/',
      changeOrigin: true,
      pathRewrite: { '^/api': '' },
    },
  }

build之后部署错误如下。
错误
部署之后请求为啥不是我target设置的地址?怎么设置才能访问我设置的地址?

@afc163
Copy link
Member

afc163 commented Dec 22, 2019

#5613
#5022
#2302

@afc163 afc163 closed this as completed Dec 22, 2019
@afc163
Copy link
Member

afc163 commented Dec 22, 2019

#2779

@afc163
Copy link
Member

afc163 commented Dec 22, 2019

umijs/umi#1421 (comment)

@Liqiankun
Copy link
Author

@afc163 恩,我还是不知道怎么解决。

@chenshuai2144
Copy link
Collaborator

@Liqiankun
Copy link
Author

Liqiankun commented Dec 23, 2019

@xiaohuoni

代理只是服务请求代理,这个地址是不会变的。
原理可以简单的理解为,在本地启了一个服务,你先请求了本地的服务,本地的服务转发了你的请求到实际服务器。所以你在浏览器上看到的请求地址还是http://localhost:8000/xxx 。以服务端是否收到请求为准

对于前端同学来说这个确实不好理解,解决方法是服务端需要设置,关键点如下,以我们为例。 更多请参考部署到不同的平台

location /api {
      proxy_pass https://ant-design-pro.netlify.com;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_set_header   Host              $http_host;
      proxy_set_header   X-Real-IP         $remote_addr;
  }

proxy_pass设置成真实服务器地址就可以了。

很多回答都是让你去看文档(对于做前端的同学真的摸不着头脑),而不直接告诉你解决问题的方法,真的不太好,如果解决了你的问题给个👍,看看解决了多少人的问题。

这样才是回答问题。如果之前的回答指出关键点,这个问题还会被一遍又一遍提问吗?

@afc163
Copy link
Member

afc163 commented Dec 27, 2019

@Liqiankun 欢迎来帮我们完善文档。

@Liqiankun
Copy link
Author

@afc163 一点个人意见而已。😂

@ZidiHu
Copy link

ZidiHu commented Aug 23, 2020

@xiaohuoni

代理只是服务请求代理,这个地址是不会变的。
原理可以简单的理解为,在本地启了一个服务,你先请求了本地的服务,本地的服务转发了你的请求到实际服务器。所以你在浏览器上看到的请求地址还是http://localhost:8000/xxx 。以服务端是否收到请求为准

对于前端同学来说这个确实不好理解,解决方法是服务端需要设置,关键点如下,以我们为例。 更多请参考部署到不同的平台

location /api {
      proxy_pass https://ant-design-pro.netlify.com;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_set_header   Host              $http_host;
      proxy_set_header   X-Real-IP         $remote_addr;
  }

proxy_pass设置成真实服务器地址就可以了。

很多回答都是让你去看文档(对于做前端的同学真的摸不着头脑),而不直接告诉你解决问题的方法,真的不太好,如果解决了你的问题给个👍,看看解决了多少人的问题。

这样才是回答问题。如果之前的回答指出关键点,这个问题还会被一遍又一遍提问吗?

Hi 朋友不好意思打扰你,我现在也碰到了这个问题试了很多不知道怎么解决。想请教一下你,你这里说要改的proxy_pass我没有在项目里找到,请问你是先用nginx部署,才会出来这个文件吗?(我目前改了config.js里的proxy,但还是无法连接服务器)
先谢谢你啦!

@Liqiankun
Copy link
Author

@ZidiHu 这个文件和我们前端的项目没关系,这个让后台同学看一下就应该可以解决问题了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants