我原来在/etc/apache2/sites-available/000-default.conf设置我的web根目录指向/home/me/www 。 由于需要一个新的项目,我需要能够设置/home/me/www/vendor/www作为自己的虚拟主机,因为localhost/blah/blah/blah导致它失败(该网站是非常可怕的,codewise,这就是为什么我已经签约工作)。
我在我的/etc/apache2/sites-available有以下configuration文件 –
project2.com.conf :
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName project2 ServerAlias localcopy ServerRoot /home/me/www/vendor/www/ DocumentRoot /home/me/www/vendor/www/ <Directory /home/me/www/vendor/www> Header set Access-Control-Allow-Origin "*" Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, eg #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
我在/etc/hosts文件中也有以下条目:
127.0.0.1 localhost 127.0.1.1 Shevat 127.0.1.2 project2.com # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
但是,当我尝试通过浏览器访问project2.com ,它显示的是/home/me/www目录的内容,因为像我上面所说的那样,我在/etc/apache2/sites-available/000-default.conf中将其设置为全局Web根目录/etc/apache2/sites-available/000-default.conf 。
有没有办法在这个例子中覆盖全球网站根/虚拟主机的设置,所以project2.com被正确访问?
在设置ServerName参数时必须指定完整的主机名:
ServerName project2.com
既然你离开'.com'apache不知道发送给你。