2012-02-01 72 views
0

我正在學習Symfony。我用2個不同的域創建了2個Symfony項目。然而,我的第二個領域指向第一個領域,不知道爲什麼。Symfony:許多不同領域的許多項目

我下面這個教程,著名Jobeet的:http://www.symfony-project.org/jobeet/1 ...麻黃鹼/ 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> 

通知我正在聽端口在教程域。我嘗試了VirtualHost 127.0.0.1的排列:和VirtualHost 127.0.0.1:。都沒有工作。 (真不知道該用)

我的/ 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/ALSO去Jobeet的頁面。我應該去包含教程部分的那個。

爲什麼不是工作??!

+0

它聽起來更像是一個網絡服務器(Apache)的問題,所有的步驟.... – 2012-02-01 19:14:17

+0

這是我的錯誤。我會在8小時後發佈 - 因爲我的聲譽在100以內 - 所以,對於明天,我會提出答案。簡短的一個:NameVirtualHost必須被調用一次,如NameVirtualHost:80 – Kani 2012-02-01 20:52:57

+0

我可以建議,如果您是第一次學習Symfony,那麼您應該學習Symfony2。從現在開始,Symfony 1將不再支持。 – lonesomeday 2012-02-02 13:30:07

回答

1

好:

在/etc/apache2/httpd.conf是足夠用:

NameVirtualHost 127.0.0.1:80 

我創造了其他ServeName教程)時重複此命令。也許這是衝突。我全部留在港口。現在它解決了。

所以,這是最後的/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的/網站,繳費用於Debian)是一樣的。

我可以訪問www.jobeet.com.localhost和www.tutorial.com.localhost

對不起,這是我的錯誤配置。

0
  1. 一個常見的錯誤是已經禁用了虛擬主機模塊爲Apache,用於啓用嘗試:sudo a2enmod virtualhost

  2. 把你的虛擬主機的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是一個腳本

+0

在'/ sites-aviables而不是'/ etc/hosts'中會有區別嗎? – Kani 2012-02-02 14:07:39

+0

'/ sites-available /'是apache讀取有關vhost和'/ etc/hosts'文件的配置的地方,它是操作系統的靜態DNS,對於虛擬主機的正常功能是必需的 – rkmax 2012-02-03 04:59:45