我在我的服务器上有2个网站。 一个我通过我的IP, xxxx / site1访问 。 另一个是注册域名www.mysite.com。
最初,我只有我的/ etc / apache / sites-available / default文件可用,但是当我尝试加载上面的任何一个网站时,我只是得到了我的/var/www/index.html输出。
我使用下面的代码为mysite.com添加了一个新的虚拟主机:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www/mysite <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/mysite> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined
当默认被禁用时,Mysite.com只会加载,但是xxxx / site1不会。
所以,我启用了具有以下代码的默认虚拟主机:
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /var/www <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined
现在, xxxx / site1可以工作,但mysite.com不会 – 而是加载/var/www/index.html页面。
我对这个问题感到困惑。 我将不胜感激一些帮助。
为了使虚拟域工作,它需要知道要映射到的主机。 在你的浏览器的http请求中,它设置了一个Host头像
Host: mysite.com
所以apache会读取这个来确定要使用的vhost条目。 你需要添加一些像
ServerName mysite.com www.mysite.com
到<VirtualHost *:80>的mysite.com虚拟主机