我有一个服务器,主机mydomain.com。 然后我有一个服务器,主机subdomain1.mydomain.com。
在subdomain1.mydomain.com服务器上,我如何制作子域名? 例如,我想创buildsubdomain2.subdomain1.mydomain.com
我有我的subdomain1.mydomain.com网站在/ home / USER / public_html,它工作得很好。 但是,当我尝试创buildsubdomain2.subdomain1.mydomain.com,它说服务器没有在浏览器中find。 我在/ etc / hosts和/etc/apache2/sites-available/subdomain2.subdomain1.mydomain.com尝试了很多configuration,没有任何运气
我可以得到一些详细的说明吗? 我到处看,每个地方都告诉你不同的,没有运气。
Ubuntu的服务器11.10带灯栈选项
Apache的configuration
你需要的是Apache VirtualHost指令。 请参阅Apache文档和一些示例 。
基本上你想在Ubuntu中做的是确保你想要使用的端口(通常是80)在/etc/apache2/ports.conf中是这样启用的:
NameVirtualHost *:80 Listen 80
接下来,你将不得不在/ etc / apache2 / sites-available中创build一个新的conf-file。 我build议将其命名为proj1.conf或proj1.mydomain.conf。
在那里你可以configurationVirtualHost如下:
<VirtualHost *:80> ServerName proj1.subdomain.domain.com DocumentRoot /var/www/proj1 ServerAdmin [email protected] # Write a seperate log per Virtualhost CustomLog /var/log/apache2/proj1.subdomain.access_log combined ErrorLog /var/log/apache2/proj1.subdomain.error_log # Maybe you want to put some restrictions on the directory <Directory /var/www/proj1> Options -Indexes +FollowSymLinks + Includes AllowOverride All # Restrict Access to certain IP's Order Deny,Allow Deny from All Allow from 127.0.0.1 IP IP IP Satisfy ALL </Directory> </VirtualHost>
请参阅Apache手册以了解您可以对指令做些什么。
要启用此网站,请将其链接到/ etc / apache2 / sites-enabled
ln -s /etc/apache2/sites-available/proj1.conf /etc/apache2/sites-enabled/proj1
现在你所要做的就是确保你的configuration是有效的,然后重新启动Apache:
apache2ctl configtest && /etc/init.d/apache2 restart
DNS
如果你运行的是虚拟机,DNS可能是由你的主机提供的,所以你可以和他谈谈关于设置DNS的问题。
当然,你将不得不在你的DNS中设置一个指向这个服务器的子域。 为此,您可以为每个子域创build一个A-或CNAME-Record,并将其指向您的服务器。
这是你的绑定区域文件的外观:
$TTL 2h @ IN SOA dns1.example.com. emailaddress.domain.com. ( 2011120701 ; serial number YYMMDDNN 1h ; Refresh 20m ; Retry 2w ; Expire 2h ; Min TTL ) @ IN NS dns1.example.com. @ IN NS dns2.example.com. @ IN MX 10 mx1.domain.com. @ IN MX 20 mx2.domain.com. @ IN A 999.999.999.999 subdomain IN A 666.666.666.666 proj1.subdomain IN CNAME subdomain *.subdomain IN CNAME subdomain
很明显,你必须用你的域名,999.999 …和666.666来代替你的域名,使用正确的IP,更改NS和MXlogging等。
有关更多详细信息,请参阅绑定手册 。
出于testing目的,您也可以编辑本地计算机上的主机文件。 这样,只有你的计算机将parsing到这个服务器的子域,所以你可以检查是否一切正常,只有如果它改变了DNS。
编辑:如果你想创build指向与子域相同目录的“sub-subdomains”,你可以在你的Apache2configuration中添加一个ServerAlias,在ServerName旁边:
ServerName subdomain.mydomain.ain ServerAlias proj.subdomain.mydomain.ain ServerAlias *.subdoamaind.mydomain.ain
DNSconfiguration将如上图所示。
卢卡斯是对的,但用这种方式来处理Vhosts可能是一个真正的痛苦。
你有没有试过免费的networkingpipe理软件? 即使我们是一个开发团队,我们使用Webmin( http://www.webmin.com/ )来完成我们的VHost,Cron作业和configurationpipe理。
你也可以拿到一份CPanel&cie的副本,但是这些都是付费的,而且通常不会给你带来比免费的基于网页的面板更多的东西。