大致说下我遇到的问题:
(1)http://test.yang.com,运行在本地的网站,nginx服务器,后端用php实现,监听的是本地80端口,hosts文件中将域名关联到127.0.0.1。域名下http://test.yang.com/api/radi... 是可以访问到的接口,打开网页是可以访问到的。
(2)http://localhost:8080,通过vue-cli搭建的一个node web服务
(3)我在/config/index.js中配置了下proxyTable:
dev: {
env: require('./dev.env'),
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'/api': {
target: 'http://test.yang.com',
changeOrigion: true,
pathRewrite: {
'^/api': '/api' // 这里不需要重写,这里写错了
}
}
},
我尝试了下面的几种配置nginx都给返回了404:
proxyTable: {
'/api': {
target: 'http://test.yang.com',
changeOrigion: true,
}
},
proxyTable: {
'/api': {
target: 'http://test.yang.com',
changeOrigion: true,
pathRewrite: {
'^/api': ''
}
}
},
proxyTable: {
'/': {
target: 'http://test.yang.com',
changeOrigion: true,
pathRewrite: {
'^/api': '/api'
}
}
},
proxyTable: {
'/': {
target: 'http://test.yang.com/api',
changeOrigion: true,
}
},
然后重启node服务,在页面中用vue-resource发出请求:
this.$http.get('/api/radio.php')
.then(function (res) {
console.log(res);
}, function(res) {
console.log(res)
})
结果发现出现nginx返回了404错误:
(4)我的nginx的test.yang.com配置如下:
我看了segmentfault上的一些关于proxyTable的文章,但是仍然不知道该怎么解决这个问题,有哪位遇到过和我类似的问题,请指教一下呗,谢谢。
PS:我还想问下,我如何才能知道我发起请求时这个proxyTable到底代理目标服务器的哪个接口地址?比如有没有个工具或者日志能够打印下。
红颜莎娜