如何正确设置虚拟主机

当我去www.example.fr时,我得到正确的DocumentRoot( /var/www/example/web ),但是当我尝试去example.fr时 ,它给了我默认的DocumentRoot( /var/www/ )。

我已经尝试了很多东西,但没有成功。

 /etc/hosts : 51.254.122.31 example.fr /etc/apache2/sites-enabled/example.fr.conf : <VirtualHost *:80> ServerAdmin [email protected] ServerName example.fr ServerAlias www.example.fr DocumentRoot /var/www/example/web/ DirectoryIndex app.php <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 </VirtualHost> 

任何想法我做错了什么?

你可能忘记了NameVirtualHost指令。 您也可以使用apachectl -S来检查已configuration的虚拟主机。