0

我现在正在学习 Symfony。我用 2 个不同的域创建了 2 个 Symfony 项目。不过,我的第二个域指向第一个域,不知道为什么。

我正在关注本教程,著名的 jobeet:http ://www.symfony-project.org/jobeet/1 ... rine/en/01

注意我的配置:

我的 /etc/apache2/httpd.conf

ServerName localhost

#From the symfony tutorial "jobeet"
# Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080

# This is the configuration for your project
<VirtualHost 127.0.0.1:80>
 ServerName www.jobeet.com.localhost
 DocumentRoot "/home/lola/sfprojects/jobeet/web"
 DirectoryIndex index.php
 <Directory "/home/lola/sfprojects/jobeet/web">
    AllowOverride All
    Allow from All
 </Directory>
 Alias /sf /home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf
<Directory "/home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf">
    AllowOverride All
   Allow from All
 </Directory>
</VirtualHost>


#Another symfony tutorial
NameVirtualHost 127.0.0.1:8081

<VirtualHost 127.0.0.1:80>
ServerName www.tutorial.com.localhost
DocumentRoot "/home/sfprojects/tutorial/web"
  DirectoryIndex index.php
  <Directory "/home/sfprojects/tutorial/web">
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf /home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf
  <Directory "/home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

请注意,我正在收听教程域中的8081端口。我尝试了 VirtualHost 127.0.0.1: 80和 VirtualHost 127.0.0.1: 81的排列。都没有奏效。(真不知道有什么用)

我的 /etc/hosts:

#From the symfony tutorial
127.0.0.1 www.jobeet.com.localhost

#From ANOTHER symfony tutorial
127.0.0.1 www.tutorial.com.localhost

之后我重新启动了 Apache。

现在,当我这样做时: http://www.jobeet.com.localhost/frontend_dev.php/我去我的 Jobeet 教程的东西,但是当我做http://www.tutorial.com.localhost/frontend_dev.php/我也去 Jobeet 页面我应该去包含教程部分的那个。

为什么工作??!

4

2 回答 2

1

出色地:

在 /etc/apache2/httpd.conf 中就足够了:

 NameVirtualHost 127.0.0.1:80

我在创建另一个ServeName ( tutorial ) 时重复了这个命令。也许这就是冲突。我把所有东西都留在了80端口。现在它解决了。

所以,这是最终的 /etc/apache2/httpd.conf:

ServerName localhost

NameVirtualHost 127.0.0.1:80

# This is the configuration for your project
<VirtualHost 127.0.0.1:80>
 ServerName www.jobeet.com.localhost
 DocumentRoot "/home/lola/sfprojects/jobeet/web"
 DirectoryIndex index.php
 <Directory "/home/lola/sfprojects/jobeet/web">
    AllowOverride All
    Allow from All
 </Directory>
 Alias /sf /home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf
<Directory "/home/lola/sfprojects/jobeet/lib/vendor/symfony/data/web/sf">
   AllowOverride All
   Allow from All
</Directory>
</VirtualHost>


#Another symfony tutorial
# DO NOT REPEAT NameVirtualHost 127.0.0.1:80 --------> ****HERE: do not repeat this****

<VirtualHost 127.0.0.1:80>
ServerName www.tutorial.com.localhost
DocumentRoot "/home/sfprojects/tutorial/web"
  DirectoryIndex index.php
  <Directory "/home/sfprojects/tutorial/web">
    AllowOverride All
    Allow from All
  </Directory>
  Alias /sf /home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf
  <Directory "/home/lola/sfprojects/tutorial/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
 </VirtualHost>

/etc/hosts(或在 /etc/apache2/sites-avaiable 中用于 debian)是相同的。

我可以访问 www.jobeet.com.localhost 和 www.tutorial.com.localhost

对不起,这是我的错误配置。

于 2012-02-02T12:42:16.007 回答
0
  1. 一个常见的错误是禁用了 apache 的虚拟主机模块,启用它尝试:sudo a2enmod virtualhost

  2. 把你的 vhost conf 放进去/etc/apache2/sites-available/name-file-with-vhost-conf

  3. 必须启用所有虚拟主机,使用sudo a2ensite name-file-with-vhost-conf

  4. apache2 必须重新加载sudo service apache2 reload

你可以试试这个github/rokemaster/virtual_hosts是一个脚本中的所有步骤

于 2012-02-02T13:26:54.160 回答