2

以下是我在 /etc/apache2/sites-available 中的虚拟主机:

<VirtualHost *:80>

DocumentRoot "/var/www/roomstays/public"

ServerName roomstays

#This should be omitted in the production environment
SetEnv APPLICATION_ENV development

<Directory "/var/www/roomstays/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

它还在 /etc/apache2/sites-enabled 文件夹上启用

以下是我的主机文件:

127.0.0.1   localhost
127.0.0.1   roomstays

# 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
ff02::3 ip6-allhosts

我在 var/www/roomstays 中配置了我的网站。但是当我进入房间时,它没有打开网站并显示此消息:

有用!

这是此服务器的默认网页。

Web 服务器软件正在运行,但尚未添加任何内容。

虚拟主机有什么问题。

4

6 回答 6

4

如何为 Zend Project 设置虚拟主机:

在位置 /var/www/ 中创建名为 'roomstays' 的项目(文件夹)

放入文件 /etc/hosts 行:

127.0.0.1 roomstays.test

在 /etc/apache2/sites-available/ 中创建名为“roomstays.conf”的文件并放入:

<VirtualHost *:80>
    ServerName 127.0.0.1
    ServerAlias roomstays.test
    DocumentRoot /var/www/roomstays/public/
    SetEnv APPLICATION_ENV "development"
    <Directory /var/www/roomstays/public/>
        Options All
        AllowOverride All
        Order Allow,Deny
        Allow From All
    </Directory>
</VirtualHost>

将该文件“roomstays.conf”复制到位置 /etc/apache2/sites-enabled/

重新启动 apache,打开浏览器并输入“roomstays.test”,这对我有用。

于 2012-06-29T10:07:55.360 回答
3

Three things to check:

1. Sites enabled

Make sure your virtual host file is in /etc/apache2/sites-enabled.

2. NameVirtualHost

Make sure you have this somewhere in the apache config:

NameVirtualHost *:80

I have it in /etc/apache2/ports.conf (can't remember if thats the standard on Ubuntu)

3. Remove default virtual host

If none of the above works, you can rename your virtual host to something like /etc/apache2/sites-enabled/000000-myhost. This will ensure your virtual host file is loaded first. Alternatively remove /etc/apache2/sites-enabled/000-default

Remember to restart apache after each change...

于 2012-06-29T19:02:55.387 回答
2

它与本地主机不冲突吗?尝试分配不同的 IP 地址,例如

127.0.0.2

并确保您已将具有别名的目录添加到 apache 日志文件目录中

希望能帮助到你!

于 2012-06-29T09:58:43.670 回答
0
<VirtualHost *:80>
    ServerName overstock.local
    DocumentRoot "C:\xampp\htdocs\overstock"
 <Directory "C:\xampp\htdocs\overstock">
    AllowOverride All
   </Directory>

 </VirtualHost>

然后将 htaccess 更改为

   Options +FollowSymLinks -MultiViews
   RewriteEngine On
   RewriteBase /overstock/

   RewriteCond %{REQUEST_URI} !/public [NC]
 RewriteRule ^(.*)$ public/$1 [L]
于 2014-12-13T19:51:51.123 回答
0

这就是我为解决这个问题所做的。复制 etc/apache2/sites-available 中的虚拟主机文件并将其粘贴到 etc/apache2/sites-enabled。转到您的浏览器并刷新,您会看到它工作

于 2014-03-05T19:21:15.820 回答
0

确保# Virtual hosts行在您的httpd.conf文件中处于活动状态。

通常,它位于:/etc/apache2/httpd.conf

要编辑文件,您需要 root 权限,因此:

sudo vim /etc/apache2/httpd.conf

取消注释该行

Include /private/etc/apache2/extra/httpd-vhosts.conf

保存文件ESC + :wq + Enter

重启你的 apache

于 2017-11-17T17:49:21.807 回答