【发布时间】:2019-09-08 09:19:18
【问题描述】:
我使用grunt-connect-proxy 将某些页面反向代理到我的 CloudFront 网站,但它无法正常工作。
环境:
- 咕哝:
^0.4.5 - grunt-contrib-connect:
^0.9.0, - grunt-connect-proxy:
^0.2.0,
我尝试了什么
- 使用
http-proxy(成功):
httpProxy.createProxyServer({target: {
protocol: 'http:',
host: 'myhostname.com',
port: 80,
},
headers: {
host: 'myhostname.com'
}}).listen(8080)
- 使用
curl(成功):
curl -v http://myhostname.com/signin
- 使用
Nginx(成功):
location ~* ^/(signin|styles|scripts) {
proxy_pass http://myhostname.com;
}
使用grunt-connect-proxy失败
connect: {
server: {
options: {
open: true,
base: ['app'],
middleware: function(connect, options, middlewares) {
if (!Array.isArray(options.base)) {
options.base = [options.base];
}
middlewares.push(modRewrite([
'^\\/customer-portal\\/((?!\\.).)*$ /index.html'
]));
middlewares.push(connect.static(options.base[0]));
middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest)
return middlewares;
}
},
proxies: [{
context: ['/signin', '/scripts', '/styles'],
host: 'myhostname.com',
port: '80',
https: false,
}]
},
}
它从 CloudFront 获取 403 代码(我不确定 CloudFront 中的 403 是否为 404)。
如果我将headers 添加到proxies
proxies: [{
...
headers: {
'host': 'myhostname.com'
}
...
}]
我从 chrome 收到 ERR_CONTENT_DECODING_FAILED 错误。
那么,正确的配置是什么?
【问题讨论】:
标签: javascript proxy gruntjs amazon-cloudfront