在 nginx 中添加和使用标头(HTTP) [英] Adding and using header (HTTP) in nginx
本文介绍了在 nginx 中添加和使用标头(HTTP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用了两个系统(两个都是 Nginx 负载均衡器,一个用作备份).
I am using two system (both are Nginx load balancer and one act as backup).
我想添加和使用一些 HTTP 自定义标头.
I want to add and use few HTTP custom headers.
以下是我的代码;
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 / {
# is included since links are not allowed in the post
proxy_pass "http://upstream0;"
}
}
备份系统
server {
listen 777;
server_name _;
#doing some other extra stuff
#use port and protocol to direct
}
我怎样才能做到这一点?
How can I achieve that?
推荐答案
要添加标题,只需将以下代码添加到要添加标题的位置块:
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屋!
查看全文