我使用grunt-connect-proxy反向代理一些页面到我的CloudFront网站,但它不能工作。
环境规划署:
^0.4.5^0.9.0,^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/signinNginx (成功):location ~* ^/(signin|styles|scripts) {
proxy_pass http://myhostname.com;
}使用grunt-connect-proxy Failded
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'
}
...
}]我从铬中得到ERR_CONTENT_DECODING_FAILED错误。那么,正确的配置是什么?
发布于 2019-04-19 07:29:40
我已经通过http-proxy用客户中间件解决了这个问题,已经放弃使用grunt-connect-proxy,代码如下:
middlewares.push(function(req, res, next) {
if(someRegex.test(req.url) {
proxy.web(req, res, {target: 'myhostname.com'})
} else {
return next();
}
})https://stackoverflow.com/questions/55739206
复制相似问题