ServerRoot "/some/path/apache"
[...] OTHER LoadModule directives [...]
LoadModule alias_module modules/mod_alias.so
Listen *:80
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
# Logs
LogLevel warn
CustomLog "logs/www.example.com_access-log" combined
ErrorLog "logs/www.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName ruby.example.com
# Logs
LogLevel warn
CustomLog "logs/ruby.example.com_access-log" combined
ErrorLog "logs/ruby.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/Ruby"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/Ruby">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName php.example.com
# Logs
LogLevel warn
CustomLog "logs/php.example.com_access-log" combined
ErrorLog "logs/php.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/php"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/php">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName django.example.com
# Logs
LogLevel warn
CustomLog "logs/django.example.com_access-log" combined
ErrorLog "logs/django.example.com_error-log"
# Index file. Add as many as required for your applications
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# Where the documents are
DocumentRoot "/some/path/apache/htdocs/django"
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
<Directory "/some/path/apache/htdocs/django">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
1 回答
由于您只能拥有1个VirtualHost(一个域,一个端口,一个IP),因此无法创建额外的VH . 您需要以其他方式“分割”到不同应用程序的路径 .
让我们假设www.example.com:
此VirtualHost是www.example.com域的基本配置 . 现在,您希望在该单个域下拥有Ruby,PHP WebApps和Django 2.0 App . 你有3个选择:
每个应用程序获取1个域,这里不适用,这是您的问题 .
在htdocs中创建一个子目录,在每个应用程序的URI中创建一个路径 .
将每个应用程序放在某个目录中,而不是在
DocumentRoot
下,并使用Alias
.使用子域 .
创建
/some/path/apache/htdocs/Ruby
,放置你的Ruby应用程序 . 这里 .将通过
http://www.example.com/Ruby
访问创建
/some/path/apache/htdocs/PHPWebApps
,放置您的PHP应用程序 . 这里 .将通过
http://www.example.com/PHPWebApps
访问创建
/some/path/apache/htdocs/Django
,放置你的Django应用程序 . 这里 .将通过
http://www.example.com/Django
访问URI值必须与目录值匹配 .
Alias
如果您不需要,或者希望URI与目录名称匹配(如2.),请使用Alias .
创建
/SOME_DIR_FOR_Ruby
,放置您的Ruby应用程序 . 这里 .添加
Alias "/Ruby" "/SOME-DIR-FOR-Ruby"
将通过
http://www.example.com/Ruby
访问创建
/SOME_DIR_FOR_PHPWebApps
,放置您的PHP应用程序 . 这里 .添加
Alias "/PHPWebApps" "/SOME_DIR_FOR_PHPWebApps"
将通过
http://www.example.com/PHPWebApps
访问创建
/SOME_DIR_FOR_Django
,放置你的Django应用程序 . 这里 .添加
Alias "/Django" "/SOME_DIR_FOR_Django"
将通过
http://www.example.com/Django
访问这是您可以使用多个VirtualHosts的地方 . 但是你必须能够创建子域 . 这可以通过DNS配置或通过您的托管服务提供商完成 .
您可以设置http://ruby.example.com,http://php.example.com,http://django.example.com . 其中每个都有1个VirtualHost,但都将映射到DNS中的相同IP .
然后设置3 VH:
在Apache 2.2上,你必须在Apache 2.4中添加
NameVirtualHost *:80
,没有,它始终是"on" .所有这些值都可以随意更改,这只是解释这个概念的一个例子 .