我想在我的Ubuntu上设置Apache2的子域名,我已经按照这个教程到了T,但每次我浏览到我的子域名时,我都会得到默认的apache登陆页面。
所以我为主域和子域都设置了独立的conf文件,
/etc/apache2/sites-available/mainsite.conf:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/mainsite/public_html ServerName www.example.com ServerAlias example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
/etc/apache2/sites-available/sub.conf:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/submainsite/public_html ServerName sub.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
我究竟做错了什么? 我没有太多的服务器端经验,所以请原谅我对此事的无知。
编辑:
这两个网站都链接了,我运行了a2ensite 。
当运行apachectl -S我得到:
default server sub.example.com (/etc/apache2/sites-enabled/000-default.conf:1) port 80 namevhost sub.example.com (/etc/apache2/sites-enabled/000-default.conf:1) port 80 namevhost sub.example.com (/etc/apache2/sites-enabled/sub.conf:1) port 80 namevhost www.example.com (/etc/apache2/sites-enabled/mainsite.conf:1) alias example.com
您将000-default.conf的默认服务器定义为sub.example.com并将其指向Apachetesting页。 因为它是第一个,它会覆盖你在sub.conf定义的第二个 sub.example.com虚拟主机。
要解决这个问题,编辑000-default.conf并ServerName sub.example.com删除ServerName sub.example.com 。