Is it possible to use variables in httpd.conf

你说的曾经没有我的故事 提交于 2019-12-03 01:08:43
noodl

Yes, kind of. You can get environment variables substituted in to the config file at start up with the ${ENVVAR} syntax. It's up to you to figure out how to set those variables before starting up the server.

http://httpd.apache.org/docs/2.2/configuring.html#syntax

Note that these variables will persist so any scripts in languages like php will be able to read them.

Also it's important to note that these values are interpreted once only when the server starts up so they're more like constants than variables.

Update

As of httpd version 2.4, see this answer instead: https://stackoverflow.com/a/15731921/498798

Try mod_macro. It actually allows you to use what are essentially variables. An example from the module's docs page gives the gist of it:

## Define a VHost Macro for repetitive configurations

<Macro VHost $host $port $dir>
  Listen $port
  <VirtualHost *:$port>

    ServerName $host
    DocumentRoot $dir

    <Directory $dir>
      # do something here...
    </Directory>

    # limit access to intranet subdir.
    <Directory $dir/intranet>
      Require ip 10.0.0.0/8
    </Directory>
  </VirtualHost>
</Macro>

## Use of VHost with different arguments.

Use VHost www.apache.org 80 /vhosts/apache/htdocs
Use VHost example.org 8080 /vhosts/example/htdocs
Use VHost www.example.fr 1234 /vhosts/example.fr/htdocs

I found a download for it at http://www.cri.ensmp.fr/~coelho/mod_macro/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!