在nginx中添加和使用标头(HTTP) [英] Adding and using header (HTTP) in nginx
本文介绍了在nginx中添加和使用标头(HTTP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用两个系统(两者都是nginx负载均衡器,一个用作备份)。我想添加和使用几个http自定义标头。请给出你的建议
I am using two system (both are nginx load balancer and one act as an backup). I want to add and use few http custom headers. Please give your suggestion
例如
upstream upstream0{
#list of upstream servers
server backend:80;
server backup_load_balancer:777 backup;
#healthcheck
}
server{
listen 80;
#Add custom header about the port and protocol (http or https)
server_name _;
location / {
proxy_pass "http://upstream0;#" is included since links are not allowed in the post
}
}
//备份系统
server{
listen 777;
server_name _;
#doing some other extra stuf
#use port and protocol to direct
}
谢谢
推荐答案
要添加标题,只需将以下代码添加到您所在的位置栏中想要添加标题:
To add a header just add the following code to the location block where you want to add the header:
location some-location {
add_header X-my-header my-header-content;
}
显然,将x-my-header和my-header-content替换为你想要添加什么。这就是它的全部内容。
Obviously, replace the x-my-header and my-header-content with what you want to add. And that's all there is to it.
这篇关于在nginx中添加和使用标头(HTTP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文