gpt4 book ai didi

amazon-web-services - 在Next.js中进行请求时,为什么会有不同的主机头?

转载 作者:行者123 更新时间:2023-12-02 18:33:55 24 4
gpt4 key购买 nike

我在Docker容器内的Elastic Beanstalk中的Amazon Web Services上托管了Next.js应用程序。我最近通过从Express.js打印req.host注意到,每当将请求发送到/_next*路由时,主机就是myid.elasticebeanstalk.com。在所有其他请求中(例如,对于实际页面或对API服务器的请求),主机都是客户端和服务器端example.com(假设我的应用托管在该地址)。
我想知道为什么会这样吗?如何将主机头(甚至将/_next*路由设置为example.com)设置?我怀疑有时这可能会导致SSL错误,因为主机将不正确。
flex beantalk配置是单个实例。 DNS记录是在AWS Route 53中配置的。带有myid.elasticebeanstalk.com的主机 header 仅出现在服务器端请求中。 example.com是CNAME,不是别名。日志在docker容器内制作。一般来说,我认为SSL证书是由AWS在Cloudfront中提供的。

最佳答案

要设置自定义HTTP header ,可以使用next.config.js中的 header 键:

module.exports = {
async headers() {
return [
{
source: '/about',
headers: [
{
key: 'x-custom-header',
value: 'my custom header value',
},
{
key: 'x-another-custom-header',
value: 'my other custom header value',
},
],
},
]
},
}
headers是一个异步函数,期望返回包含 sourceheaders属性的对象的数组: source是传入的请求路径模式。 headers是具有 keyvalue属性的 header 对象的数组。

关于amazon-web-services - 在Next.js中进行请求时,为什么会有不同的主机头?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63871590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com