我将ubuntu更新为13.10后设置虚拟主机有困难!! 这是我试过的:
启动终端并键入:
sudo a2enmod vhost_alias
如果您没有收到任何错误消息,并且您的回复如下所示,那么您就是在正确的轨道上.
Enabling module vhost_alias. Run '/etc/init.d/apache2 restart' to activate new configuration!
接下来要做的是通过键入来访问sites-available目录
cd /etc/apache2/sites-available/
好的,现在我们在apaches目录中,其中虚拟主机的所有定义文件都是.我们想要复制默认模板一,密码命名为default
sudo cp default our-test-site
这将创建一个名为our-test-site的默认模板的副本(当然,您应该将其替换为您想要的任何内容).让我们编辑它,输入
sudo gedit our-test-site
这将在编辑器中打开文件,下面是默认vhost文件的内容(如果你做了一些自定义,通常是YMMV)
ServerAdmin webmaster@localhost DocumentRoot /var/www Options FollowSymLinks AllowOverride None Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined Alias /doc/ "/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
我们需要添加一行并编辑两行.
在DocumentRoot指令的正上方添加ServerName my-test-site.local(在第4行的前面).
在第4行编辑DocumentRoot/var/www路径并将其设置为/ path-to-the-test-site-WITHOUT-trailing-slash.看起来应该是这样的
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
如果你没有注意到我的微妙提示,那么路径末尾不应该有一个斜杠.
编辑第9行的路径并将其设置为/ path-to-the-test-site-WITH-trailing-slash /.看起来应该是这样的
DocumentRoot /path-to-the-test-site-WITHOUT-trailing-slash
如果您没有注意到我的微妙提示,那么在路径的末尾应该是一个尾随斜杠.
你已经完成了虚拟主机文件的设置.键入即可启用它
sudo a2ensite our-test-site
响应应该如下所示
Enabling site our-test-site. Run '/etc/init.d/apache2 reload' to activate new configuration!
此时虚拟主机设置已完成,剩下的就是告诉服务器我们的test-site.local应该被重新发送到127.0.0.1.我们这样做是打字
sudo gedit /etc/hosts
并在localhost(第1行)之后添加127.0.0.1 our-test-site.local.
整个hosts文件看起来应该是这样的
127.0.0.1 localhost 127.0.0.1 our-test-site.local 127.0.1.1 ubuntu-vm # 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
保存它,关闭编辑器,最后输入
sudo /etc/init.d/apache2 restart
要么
sudo apache2ctl restart
所以,你去,你的虚拟主机设置,打开浏览器并输入http://our-test-site.local并享受.
更新:如果您在访问localhost的内容时遇到问题,则应将ServerName localhost添加到默认虚拟主机中(如上所述,用于新虚拟主机).然后禁用并启用站点,并重新启动apache
sudo a2dissite default sudo a2ensite default sudo /etc/init.d/apache2 restart
更新2:在新的虚拟主机文件中,您应该更改您的
AllowOverride None
至
AllowOverride All
对于前两个目录节点(/ one和具有站点路径的节点).这将允许所有.htaccess文件正常工作并允许重定向.
当然不要忘了
sudo a2dissite our-test-site sudo a2ensite our-test-site sudo /etc/init.d/apache2 restart
Waqleh.. 6
问题是,对于Apache 2.4/ubuntu 13.10及更高版本,站点可用的文件就像name.conf
而不是
sudo cp default our-test-siteof
我是这样做的
sudo cp default.conf our-test-site.conf
等等.
问题是,对于Apache 2.4/ubuntu 13.10及更高版本,站点可用的文件就像name.conf
而不是
sudo cp default our-test-siteof
我是这样做的
sudo cp default.conf our-test-site.conf
等等.