【问题标题】:Apache returning null for environment variables in headerApache 在标头中为环境变量返回 null
【发布时间】:2022-02-01 22:29:47
【问题描述】:

我现在正在尝试对我的 apache 测试站点进行故障排除。我需要在标头中返回 mod_rewrite 变量,以便我可以看到发生了什么。但是,当我尝试在标题中设置它们时,我得到 null

服务器版本:Apache/2.4.51 (Fedora)

配置

<VirtualHost mysite.local:80>
  ServerName mysite
  DocumentRoot /var/www/html/mysite
  Header always set TestHeader "%{SERVER_NAME}e"

curl 的输出

curl -I http://mysite.local/index.html

HTTP/1.1 200 OK
Date: Tue, 01 Feb 2022 02:05:42 GMT
Server: Apache/2.4.51 (Fedora)
TestHeader: (null)
Last-Modified: Tue, 25 Jan 2022 19:37:28 GMT
ETag: "15-5d66d372009de"
Accept-Ranges: bytes
Content-Length: 21
Content-Type: text/html; charset=UTF-8

此外,mod_headers 和 mod_rewrite 已启用

$ grep -R 'mod_rewrite' conf.modules.d/
conf.modules.d/00-base.conf:LoadModule rewrite_module modules/mod_rewrite.so
$ grep -R 'mod_headers' conf.modules.d/
conf.modules.d/00-base.conf:LoadModule headers_module modules/mod_headers.so

我是否缺少某些设置或配置?

【问题讨论】:

    标签: apache mod-rewrite apache2.4 mod-headers


    【解决方案1】:

    尝试在Header set 之前添加PassEnv SERVER_NAME

    更多信息请见PassEnv - mod_env - Apache HTTP Server Version 2.4 Documentation

    【讨论】:

    • 我做了,没用
    • @user2446214 可能 SERVER_NAME 在您添加标头时实际上没有设置。
    猜你喜欢
    • 2018-09-30
    • 2021-05-14
    • 2020-01-02
    • 2016-11-11
    • 2015-05-14
    • 1970-01-01
    • 2020-09-04
    • 2015-06-29
    • 1970-01-01
    相关资源
    最近更新 更多