如果存在特殊标题,则NGINX应添加参数

发布于 2025-02-11 18:50:53 字数 386 浏览 0 评论 0原文

Nginx是否有任何简单的方法可以在路径上添加参数?
我是Nginx的新手,无论如何与配置有些混淆。 (长期Apache用户):

示例我要做的事情:

Request Header : 

GET /xxxx/yyyy?page=10 HTTP/1.1.
x-my-special : true.

If (x-my-special is true) ; then 

  add_parameter(x-my-special=true) 


Result before the web application get it : 

Path : /xxxx/yyyy?page=10&x-my-special=true

如果您能为我提供帮助或有提示,那就非常好。

is there any simple way with nginX to add a parameter to the path ?
I am new to nginX and a bit confused with the configuration anyway. (long term Apache user) :

Example what I am trying to do:

Request Header : 

GET /xxxx/yyyy?page=10 HTTP/1.1.
x-my-special : true.

If (x-my-special is true) ; then 

  add_parameter(x-my-special=true) 


Result before the web application get it : 

Path : /xxxx/yyyy?page=10&x-my-special=true

Would be really nice if you could help or have a hint for me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

霞映澄塘 2025-02-18 18:50:53

如果

/xxxx/yyyy?x-my-special=true&page=10

对您来说

/xxxx/yyyy?page=10&x-my-special=true

是可以的,那么最简单的方法将是

if ($http_x_my_special = true) {
    rewrite ^ $uri?x-my-special=true;
}

,或者,从x-my特殊 header中添加任何非空值:

if ($http_x_my_special) {
    rewrite ^ $uri?x-my-special=$http_x_my_special;
}

如果块应应放置在服务器配置级别。但是,根据您的实际配置,它可能会多次执行该块,而正确放置它的唯一方法是查看您的整个NGINX配置。

If

/xxxx/yyyy?x-my-special=true&page=10

instead of

/xxxx/yyyy?page=10&x-my-special=true

will be ok to you, the simplest way will be

if ($http_x_my_special = true) {
    rewrite ^ $uri?x-my-special=true;
}

or, to add any non-empty value from the X-My-Special header:

if ($http_x_my_special) {
    rewrite ^ $uri?x-my-special=$http_x_my_special;
}

This if block should be placed at the server configuration level. However, depending on your actual config, it may come this block will be executed more than once, and the only way to place it properly will be to see your whole nginx configuration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文