创建通配符子域名使用Apache虚拟主机 [英] Creating Wildcard Sub Domain Using Apache VirtualHost
问题描述
我想有这种情况:
-
如果使用此URL用户请求:
example.com
或www.example.com
,
用户将看到的index.php
此目录中的/家庭/ ADMIN1 /的public_html /
-
但在使用例如其他子域(通配符)用户请求:
freediscount.example.com
,用户将看到索引。 PHP
此路径:/home/admin1/public_html/userweb/freediscount.example.com
技术支持建议我用这个方法:<一href=\"http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html\">http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html
根据该教程中,PHP有一个新的工作......在特定的文件夹重定向时子域用户的请求。我不喜欢这种方法。对我来说,这将是更好,如果Apache可以处理这个问题。
几乎接近我需要的是这种方法:<一href=\"http://stackoverflow.com/questions/758351/virtualhost-for-wildcard-subdomain-and-static-subdomain\">Virtualhost通配符域和子域的静态
不过,我有虚拟主机
设置问题,如何创建虚拟主机
正确的这种情况?
这里是我做了什么,但没有工作:
##,我认为这个人是www或者加www,具有南国自动生成
&LT;虚拟主机XX.XX.XX.XX:80&GT;
服务器名称example.com
ServerAlias www.example.com
的DocumentRoot /家庭/ ADMIN1 /的public_html
&LT; /虚拟主机&GT;##这是我正在试图增加
&LT;虚拟主机XX.XX.XX.XX:80&GT;
服务器名称example.com
的DocumentRoot /家庭/ ADMIN1 /的public_html / userweb / *
&LT; /虚拟主机&GT;
通配符子域是绝对有可能使用Apache虚拟主机。
我有基本相同的要求,并设法得到它与Apache的 mod_vhost_alias.so
模块的工作。在你的 HTTP-vhosts.conf试试这个
文件:
的DocumentRoot/家/ ADMIN1 /的public_html / userweb /
&LT;目录/家/ ADMIN1 /的public_html / userweb /&GT;
选择无
设置AllowOverride无
为了允许,拒绝
所有允许
&LT; /目录&GT;&LT;虚拟主机*:80&GT;
的DocumentRoot /家庭/ ADMIN1 /的public_html /
服务器名www.example.com
&LT; /虚拟主机&GT;&LT;虚拟主机*:80&GT;
VirtualDocumentRoot /home/admin1/public_html/userweb/%1.example.com/
&LT; /虚拟主机&GT;&LT;虚拟主机*:80&GT;
的DocumentRoot /家庭/ ADMIN1 /的public_html /
服务器名称example.com
&LT; /虚拟主机&GT;
请注意,我没有测试过这一点,但它是pretty接近为我工作的解决方案。
我的解决方案的全部细节在这里:
<一href=\"http://www.calcatraz.com/blog/wildcard-subdomains-in-apache-1422\">http://www.calcatraz.com/blog/wildcard-subdomains-in-apache-1422
I want to have this situation :
if user request using this URL :
example.com
orwww.example.com
, user will seeindex.php
in this directory/home/admin1/public_html/
but when user request using other sub domain (wildcard) for example :
freediscount.example.com
, user will seeindex.php
in this path :/home/admin1/public_html/userweb/freediscount.example.com
technical support on my hosting suggest me to use this method : http://www.wiredstudios.com/php-programming/setting-up-wildcard-dns-for-subdomains-on-cpanel.html
based on that tutorial, the PHP has a new job... to redirect on specific folder when user request with sub domain. I don't like this method. for me, it would be better if Apache can handle this.
nearly close to what I need is this method : Virtualhost For Wildcard Subdomain and Static Subdomain
but, I have a problem with VirtualHost
setting, how to create VirtualHost
correctly for that situation?
here's what I've done but didn't work :
## I think this one is for www or without www, automatically generated with WHM
<VirtualHost xx.xx.xx.xx:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/admin1/public_html
</VirtualHost>
## Here's what I'm trying to add
<VirtualHost xx.xx.xx.xx:80>
ServerName example.com
DocumentRoot /home/admin1/public_html/userweb/*
</VirtualHost>
Wildcard sub-domains are definitely possible using Apache virtual hosts.
I had basically the same requirements and managed to get it working with Apache's mod_vhost_alias.so
module. Try this in your http-vhosts.conf
file:
DocumentRoot "/home/admin1/public_html/userweb/"
<Directory "/home/admin1/public_html/userweb/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName www.example.com
</VirtualHost>
<VirtualHost *:80>
VirtualDocumentRoot /home/admin1/public_html/userweb/%1.example.com/
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /home/admin1/public_html/
ServerName example.com
</VirtualHost>
Note that I haven't tested this, but it's pretty close to the solution that worked for me.
Full details of my solution are here: http://www.calcatraz.com/blog/wildcard-subdomains-in-apache-1422
这篇关于创建通配符子域名使用Apache虚拟主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!