开发环境:
前端react: localhost:3000
后端restful api:192.168.33.3:8080
浏览器可以正常访问后端restful api:
react使用axios访问后端api:
function fetchArticleList() {
axios.get('/api/articles').then((response) => {
return response.data;
}).catch(function (error) {
//...
}).then(function () {
//...
});
}
localhost机器上安装nginx,配置如下:
server {
listen 3000;
server_name localhost;
location /api {
proxy_pass http://192.168.33.3:8080/;
}
location /= {
root html;
index index.htm index.html;
}
location ~ \.(htm|html|js|css|jpg|png|gif|eot|svg|ttf|woff|woff2)$ {
root html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
问题:
在浏览器中访问localhost:3000/api/articles,出现如下错误:
是哪里没有配置正确?
你的react用什么启动的?没配合webpack,所以要用Nginx?
端口占用了,让其中一个换一个不就好了么?比如启动react的服务端口换成
3001