动态配置的虚拟主机
喂! 我想为将来使用 mod_rewrite 创建的所有子域准备一个动态虚拟主机。所有子域的配置方式几乎相同,因此我考虑使用动态 VH 配置。 我希望每个子域的文档根目录为 /home/user/public_html/subdomainName。
我尝试过以下配置,但没有成功:
<VirtualHost xxx.xxx.xxx.xxx:80>
# get the server name from the Host: header
UseCanonicalName Off
<Directory /home/user/public_html/>
# ExecCGI is needed here because we can't force
# CGI execution in the way that ScriptAlias does
Options FollowSymLinks ExecCGI
</Directory>
RewriteEngine On
# a ServerName derived from a Host: header may be any case at all
RewriteMap lowercase int:tolower
#rule that is suposed to set document root of virtual host!???
RewriteRule ^([a-z-]+)\.domain\.com/?(.*) /home/user/public_html/$1/$2
</VirtualHost>
规则或某些东西似乎是错误的并且不适用。我以前从未使用过动态 VH,所以我不知道我错在哪里......
Helo!
I would like to prepare a dynamic virtual host for all subdomains that will be created in future using mod_rewrite. All subdomains would be configured prety much same way, so i thought of using dynamic VH configuration.
I want my document root for each subdomain to be /home/user/public_html/subdomainName.
I've tried with following configuration, but had no success:
<VirtualHost xxx.xxx.xxx.xxx:80>
# get the server name from the Host: header
UseCanonicalName Off
<Directory /home/user/public_html/>
# ExecCGI is needed here because we can't force
# CGI execution in the way that ScriptAlias does
Options FollowSymLinks ExecCGI
</Directory>
RewriteEngine On
# a ServerName derived from a Host: header may be any case at all
RewriteMap lowercase int:tolower
#rule that is suposed to set document root of virtual host!???
RewriteRule ^([a-z-]+)\.domain\.com/?(.*) /home/user/public_html/$1/$2
</VirtualHost>
The rule or somethinh seems to be wrong andit doesn't apply. I've never worked with dynamic VH before so i have no idea where i'm wrong...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是在您之前很多人都有过的需求。因此,有一个 apache 模块可以为您执行此操作 mod_vhost_alias http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
This is a need a lot of people had before you. So there's an apache module which can do that for you mod_vhost_alias http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html
您还可以使用通配符 dns 来代替动态虚拟主机,这意味着将 {anything}.yourdomain.tld 配置为指向您的服务器。
这也将为每个域提供相同的文档根。
请注意,您需要将
ServerAlias *.yourdomain.tld
添加到虚拟主机条目instead of dynamic virtual hosts, you can also do this using wildcard dns which means configuring {anything}.yourdomain.tld to point to your server.
This will also get you same document root for each domain.
note that you will need to add
ServerAlias *.yourdomain.tld
to the virtual host entry使用 RewriteRule 您无法访问域名。还对该部分使用 RewriteCond 并使用 %1 等进行反向引用。
唯一的问题是这将创建一个在子域名字符串前面添加的连续循环。所以我通常做的是为子域创建一个单独的文件夹,例如“子域”
With RewriteRule you can't access the domainname. Also use RewriteCond for that part and use %1 etc. for backreference.
The only problem is this will create a continues loop of prepending the subdomainname string. So what I normally do is create a separate folder for subdomains, like 'subdomains'