Sharing configuration between several VHosts

自闭症网瘾萝莉.ら 提交于 2019-12-08 04:23:49

问题


I'm managing a httpd installation with several sites running on it, each defined within it's own <VirtualHost> directive. There are several configuration variables (most of them from core as well as some php_flag/php_value) that are exactly the same for several of the sites defined.

I would like to be able to define a configuration set that will apply to several <VirtualHost> directives at the same time (to remove redundancy and make the server maintenance a little bit easier).

I have considered using <Directory>, however many of the configuration values I need to set, cannot be modified from within <Directory>. I have also tried to define another <VirtualHost> section, containing all of the sites I want to share the config in

<VirtualHost xx.xx.xx.xx:80 yy.yy.yy.yy:80>
    ...config...
</VirtualHost>

but this just results in

VirtualHost xx.xx.xx.xx:80 overlaps with VirtualHost yy.yy.yy.yy:80, the first has precedence, perhaps you need a NameVirtualHost directive

Any idea how I can achieve this?


回答1:


In apache documentation this is called mass VirtualHost configuration.

Several solutions exists:

  • mod_vhost_alias, with the VirtualDocumentRoot instructions, but it is usually too simple and managing other variations than DocumentRoot and the domain name are quite hard.
  • advanced mod_rewrite tricks, as mod_rewrite is a swiss knife and can do everything, but everything seems quite complex when it is done with mod_rewrite.
  • mod_macro is a module that allow the usage of an infinite list of macros with parameters that can be reused between Virtualhosts (for example), so you can add more parameters than DocumentRoot and ServerName and share single configurations files between serval Vhosts.


来源:https://stackoverflow.com/questions/18714293/sharing-configuration-between-several-vhosts

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