我正在尝试设置动态vHost,但遇到了一些麻烦。它不允许我设置多个ServerAlias。
<VirtualHost *:80>
ServerAlias *.com
ServerAdmin michael.ian.curry@gmail.com
VirtualDocumentRoot /var/www/%1/production/html
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
</VirtualHost>
以上vHost仅适用于' .com'我需要它才能用于'www。 .com'和'* .com' 我假设将ServerAlias设置为将修复它,但它无法正常工作。
ServerAlias *.com www.*.com
如果您有任何见解,请回复
- MichaelCurry
==编辑1 ==
示例redcrusher.com和www.redcrusher.com
==编辑2 ==
以下代码无效
ServerAlias www.*.com *.com
答案 0 :(得分:14)
想出来了!
'www。*。com'必须在'* .com'之前执行这是因为ServerAlias正在设置一个动态域,并且必须在存在“较小”别名之前存在。
示例:'www。*。com','dev。*。com','asdf。*。com'THEN'* .com'
vHost文件[production.conf]:
<VirtualHost *:80>
ServerAlias www.*.com
VirtualDocumentRoot /var/www/%2/production/html
ServerAdmin michael.ian.curry@gmail.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
</VirtualHost>
<VirtualHost *:80>
ServerAlias *.com
VirtualDocumentRoot /var/www/%1/production/html
ServerAdmin michael.ian.curry@gmail.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
</VirtualHost>
我希望这可以帮助其他任何有这个问题的人!
- MichaelCurry
答案 1 :(得分:4)
你必须像这样使用
ServerAlias www.domain.com domain.com
ServerAlias *.domain.com
如果您想使用那种必须遵循秩序的方式
ServerAlias www.*.com *.com
问题在于
VirtualDocumentRoot /var/www/%1/production/html
使用动态VirtualDocumentRoot表示
for redcrusher.com VirtualDocumentRoot是
/var/www/redcrusher/production/html
和www.redcrusher.com VirtualDocumentRoot是
/var/www/www.redcrusher/production/html
我认为拆分ServerAlias分三部分解决
ServerAlias www.*.com
VirtualDocumentRoot /var/www/%1/production/html/
ServerAlias *.*.com
VirtualDocumentRoot /var/www/%2/production/html/%1
ServerAlias *.com
VirtualDocumentRoot /var/www/%1/production/html
我认为应该工作
VirtualDocumentRoot:
redcrusher.com
/var/www/redcrusher/production/html
www.redcrusher.com
/var/www/redcrusher/production/html/
sub.redcrusher.com
/var/www/redcrusher/production/html/sub