我想在Apache服务器的httpd.conf
配置文件中定义一个变量。
例如:变量静态路径 = C:\codebase\snp_static
我希望在httpd.conf
中任何需要的地方使用这个变量(静态路径)。
请告诉我如何在httpd.conf
文件中定义一个变量?
我想在Apache服务器的httpd.conf
配置文件中定义一个变量。
例如:变量静态路径 = C:\codebase\snp_static
我希望在httpd.conf
中任何需要的地方使用这个变量(静态路径)。
请告诉我如何在httpd.conf
文件中定义一个变量?
Define
(最好在第一行)Define
变量名
变量值
以此方式进行声明:#The line below creates the variable [static_path]
Define static_path C:/codebase/snp_static
ServerRoot = ${static_path}
...
DocumentRoot = ${static_path}
...
<Directory ${static_path}>
...etc.
您甚至可以将多个变量结合起来:
#Below, I am going to combine variables [server_space] and [static_path]
Define server_space c:/
Define static_path codebase/snp_static
...
ServerRoot = ${server_space}${static_path}
...
DocumentRoot = ${server_space}${static_path}
...
<Directory ${server_space}${static_path}>
...etc.
这是一个关于Apache HTTP服务器核心模块的文档链接。mod_define
。毕竟,提供的文档也适用于2.4(及以上版本)。但以防万一我真的非常错误:https://people.apache.org/~rjung/mod_define/mod_define.html 你有没有尝试在你的服务器上不进行修改地使用它? - OmarApache 2.4 我进行了研究,这是我找到并测试成功的解决方法,使用 httpd_z.exe -t -D DUMP_RUN_CFG 进行测试。
RESULTS:::
ServerRoot: "C:/path/core/apache2"
Main DocumentRoot: "C:/path/apache/htdocs"
Main ErrorLog: "C:/path/core/apache2/logs/error.log"
Mutex rewrite-map: using_defaults
Mutex default: dir="C:/path/core/apache2/logs/" mechanism=default
PidFile: "C:/path/core/apache2/logs/httpd.pid"
Define: DUMP_RUN_CFG
Define: US_ROOTF=C:/path **THIS IS THE ROOT PATH VARIABLE I JUST MADE**
Define: php54
#<IfDefine TEST>
# Define servername test.example.com
#</IfDefine>
#<IfDefine !TEST>
# Define servername www.example.com
# Define SSL
#</IfDefine>
#DocumentRoot /var/www/${servername}/htdocs
<IfDefine US_ROOTF>
Define US_ROOTF C:/PATH **The path i want the variable for**
</IfDefine>
<IfDefine !US_ROOTF>
Define US_ROOTF C:/PATH **The path i want the variable for**
# Define SSL
</IfDefine>
#DocumentRoot /var/www/${servername}/htdocs OPTIONS ON HOW TO USE
EXAMPLE of use
ServerRoot = ${US_ROOTF}
<IfDefine php54>
LoadFile "${US_ROOTF}/core/php54/icudt53.dll"
PHPIniDir "${US_ROOTF}/core/php54/php_production.ini"
有人曾经告诉过我,在将内容提供给互联网时,永远不要使用直接的硬路径,而应该使用变量来帮助保护您的系统。
我通过自己的痛苦经历证实了这一点。现在,我终于找到了如何为处理 Apache 的所有服务设置变量的方法。
希望对您有所帮助。
虽然来晚了,但最近我遇到了这个问题,并且像这样解决了它:
DEFINE path "C:\path/to the/directory"
稍后可以这样使用:
DocumentRoot ${path}
<Directory ${path}>
注意:在路径中,在驱动器字母后使用 \