Apache newb在这里。 我读了几个教程,我不知道我做错了什么。
我有我的默认网站启用,并且一个正常工作:
<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 Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
所以我想添加第二个网站www.example.com。 我更新了我的主机文件:
192.168.1.148 sam-NV53 # Added by NetworkManager 127.0.0.1 localhost.localdomain localhost ::1 sam-NV53 localhost6.localdomain6 localhost6 127.0.1.1 sam-NV53 www.example.com localhost.localdomain localhost # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts
我定义了我的新网站
<VirtualHost *> ServerAdmin [email protected] ServerName www.example.com ServerAlias example.com DirectoryIndex index.html DocumentRoot /var/www/ </VirtualHost>
由于我的新网站的DocumentRoot与我的默认网站的DocumentRoot相同,所以我希望能从我的默认站点看到index.html 。 但是,我从网上看到了example.com。 我在这里错过了什么?
编辑
显然没有人注意到我在我的主机文件中的input是反向的。 我把它改成:
127.0.0.1 geekspeak.dev
现在起作用了。 谢谢各位的意见 :)
无论你在哪里
<VirtualHost>
必须与您所列的内容相符
NameVirtualHost
所以,如果你有
NameVirtualHost *:80
所有虚拟主机条目的端口80必须看起来像
<VirtualHost *:80>
所以把*换成*:80就像在你的第一个例子中,它应该去正确的位置
尝试使用除example.com,www.example.com或其他衍生产品以外的内容。 这些名称由IANA保留用于文档。 我使用自己的Apache服务器来尝试在www.example.comconfiguration一个虚拟主机,而且我总是被redirect到IANA页面,但之后我将其更改为www.someserver.dev ,一切正常。
祝你好运
有几件事你可以尝试:
example.com作为您网站的名字。 hosts文件。 这在某些情况下可能是有用的,但在这种情况下我不明白它是如何需要的。 somesite.com ,则可以根据需要自由创build子域test.somesite.com或任意数量的其他域。 我试过这个使用virtualbox。 主机操作系统 – Win7,来宾操作系统 – Ubuntu服务器。
1)创buildwww.yourdomain.com在/ etc / apache2 / sites-available /
<virtualhost *:80> # i recommend adding your interface IP here ServerAdmin [email protected] ServerName yourdomain.com ServerAlias www.yourdomain.com DirectoryIndex index.html DocumentRoot /var/www/main/htdocs LogLevel warn ErrorLog /var/www/main/logs/error.log CustomLog /var/www/main/logs/access.log combined </virtualhost>
2)在/ var / www中创build目录
mkdir -p /var/www/main/htdocs mkdir -p /var/www/main/logs
修改这些目录的权限
3)在apache2中启用网站
a2ensite www.yourdomain.com
4)编辑/ etc / apache2 / sites-available / default并删除DocumentRoot和最后一行之间的所有行。
5)重新启动或重新加载apache2
6)编辑您的主机文件www.yourdomain.com然后尝试一下。
这在我的testing服务器上工作。