加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

nginx – $http_referer的行为类似于$document_uri

发布时间:2020-12-13 21:24:19 所属栏目:Nginx 来源:网络整理
导读:我需要在ssi include中设置调用者参数作为当前的uri,但$document_uri工作异常 包含ssi的模板部分包括:

我需要在ssi include中设置调用者参数作为当前的uri,但$document_uri工作异常

包含ssi的模板部分包括:

确实,$http_referer,而不是$document_uri

Nginx日志格式:

log_format  subtimed  '$remote_addr - $remote_user [$time_local] '
                      '"INC $uri$is_args$args" $status $bytes_sent "$http_referer" '
                      '"$http_user_agent"

/面板/的Nginx位置:

location /panel/ {
            internal;
            ssi  on;
            proxy_set_header        Host panel.domain.zone;
            proxy_method            GET;
            proxy_pass              http://panel.domain.zone/;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_connect_timeout   1s;
            proxy_send_timeout      2s;
            proxy_read_timeout      2s;
            proxy_intercept_errors  on;
            log_subrequest on;
    }

我打开页面http://devel.domain.zone,我看到在nginx日志中:

xxx.xxx.xxx.xxx - - [15/Oct/2015:18:29:31 +0300] "INC /panel/?project=project_name&color=dark&caller=http://devel.domain.zone" 200 0 "http://devel.domain.zone/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0"

好的,请转到第http://devel.domain.zone/sec/?theme=102页
Nginx日志:

xxx.xxx.xxx.xxx - - [15/Oct/2015:18:30:29 +0300] "INC /panel/?project=project_name&color=dark&caller=http://devel.domain.zone/sec/?theme=102" 200 0 "http://devel.domain.zone/sec/?theme=102" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0"

原来,$http_referer的行为像$document_uri …
所以,如果我在ssi include中设置$document_uri而不是$http_referer,我在nginx日志中看到如下所示:

xxx.xxx.xxx.xxx - - [15/Oct/2015:18:30:29 +0300] "INC /panel/?project=project_name&color=dark&caller=/ga/ga.js" 200 0 "http://devel.domain.zone/sec/?theme=102" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:41.0) Gecko/20100101 Firefox/41.0"

WTF?!!在什么时候计算$document_uri变量?如何将变量传递到include中:作为一个名称或一个值?

最佳答案
你不是很清楚你在问什么.你做了什么?你期望什么?你得到了什么?

根据http://nginx.org/r/%24document_uri,$document_uri与$uri相同(并且不应该与$request_uri混淆,这是一个完全不同的变量).

反过来,$uri变量也很清楚(http://nginx.org/r/%24uri年) – 以我自己的话来说,它本质上是nginx位置/重写状态机的状态 – 所有内部重写,你执行更改这个变量,它是基本上总是在被重写的过程中.另一个重要的一点是,除非你可以自己修改这个变量,否则它也会丢失$is_args $args部分,并且它也被归一化,就像location匹配一样,因为位置匹配实际上完全是针对$uri完成的.

BTW,有一些有趣的事情,你可以用$uri与一堆重写指令,看看http://mdoc.su/(确保看看它的nginx.conf!)和一个更简单但仍然值得注意和有用的代码示例也可用on ServerFault: “How do I verify site ownership on Google Webmaster Tools through nginx.conf?”.

如果你对C中如何实现这些事情更加好奇,可以通过以下方式开始你的旅程:

> http://ngx.su/src/http/ngx_http_variables.c#ngx_http_core_variables
> http://ngx.su/src/http/ngx_http_variables.c#ngx_http_variable_request
> http://ngx.su/src/http/ngx_http_request.h#ngx_http_request_s
> http://ngx.su/src/http/ngx_http_request.h#uri

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读