修改nginx反向代理请求的Header 需要使用到proxy_set_header和add_header指令。其中: proxy_set_header 来自内置模块ngx_http_proxy_module, 用来重定义发往代理服务器服务器的请求头。参考:https://blog.csdn.net/weixin_41585557/article/details/82426784 示例: location ^~/test/ { proxy_pass http://127.0.0.1:8001$request_uri; proxy_set_header host $http_host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; } headers-more-nginx-module 模块 headers-more-nginx-module 模块用于添加、修改或清除 请求/响应头,该模块不是nginx自带的,默认不包含该模块,需要另外安装。 Github地址:https://github.com/openresty/headers-more-nginx-module 安装: $ wget 'http://nginx.org/download/nginx-1.13.6.tar.gz' $ tar -xzvf nginx-1.13.6.tar.gz $ cd nginx-1.13.6/ # 假设Nginx安装在 /opt/nginx/ 目录 $ ./configure --prefix=/opt/nginx --add-module=/path/to/headers-more-nginx-module $ make $ make install 在Nginx配置文件里加上: load_module /path/to/modules/ngx_http_headers_more_filter_module.so; 该模块主要有4个指令: more_set_headers 用于添加、修改、清除响应头 more_clear_headers 用于清除响应头 more_set_input_headers 用于添加、修改、清除请求头 more_clear_input_headers 用于清除请求头 # 示例 # set the Server output header more_set_headers 'Server: my-server'; # set and clear output headers location /bar { more_set_headers 'X-MyHeader: blah' 'X-MyHeader2: foo'; more_set_headers -t 'text/plain text/css' 'Content-Type: text/foo'; more_set_headers -s '400 404 500 503' -s 413 'Foo: Bar'; more_clear_headers 'Content-Type'; # your proxy_pass/memcached_pass/or any other config goes here... } # set output headers location /type { more_set_headers 'Content-Type: text/plain'; # ... } # set input headers location /foo { set $my_host 'my dog'; more_set_input_headers 'Host: $my_host'; more_set_input_headers -t 'text/plain' 'X-Foo: bah'; # now $host and $http_host have their new values... # ... } # replace input header X-Foo *only* if it already exists more_set_input_headers -r 'X-Foo: howdy';
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
2021-12-01 vc qt dll
2021-12-01 qoci 编译完 放置位置 具体根据情况
2021-12-01 qt 开发发布于 windeploy.exe
2021-12-01 qt oracle
2021-12-01 QOCIDriver unable to create environment
2021-12-01 qt qoci 测试验证
2021-12-01 calling 'lastError' with incomplete return type 'QSqlError' qsqlquer