2014-03-26 12 views
1

考慮以下Apache配置:阿帕奇不是服務於/主頁,但正確地投放在/ var頁

$ cat /etc/apache2/sites-available/yair.conf 
<VirtualHost *:80> 
     ServerName localhost 
     DocumentRoot /home/yair/code/business/public_html 

     <Directory /home/yair/code/business/public_html/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride All 
       Order allow,deny 
       allow from all 
     </Directory> 

     <Directory /> 
       AllowOverride None 
       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 

</VirtualHost> 

public_html目錄配置如:

$ cat /etc/hosts 
127.0.0.1  localhost 

$ pwd 
/home 
$ ls -la | grep yair 
drwxrwxrw- 49 yair  www-data 4096 Mar 26 10:33 yair 

$ cd yair/ 
$ ls -la | grep code 
drwxrwxrw- 4 yair www-data 4096 Mar 26 09:10 code 

$ cd code 
$ ls -la | grep business 
drwxrwxrw- 8 yair www-data 4096 Mar 26 09:11 business 

$ cd business/ 
$ ls -la | grep public 
drwxrwxrw- 6 yair www-data 4096 Mar 26 10:33 public_html 

$ cd public_html/ 
$ ls -la | grep index.html 
-rwxrwxrw- 1 yair www-data 4566 Mar 26 09:11 index.html 

當我改變DocumentRoot/var/www/,並將文件放在那裏,Apache按預期爲它們服務。但是,使用上面的配置Apache抱怨:

您沒有權限訪問此服務器上的/index.html。

什麼可能是配置錯誤?這在Ubuntu 13.10上。

+0

你從服務器訪問呢? – krowe

+0

是的,我正在從Firefox瀏覽器訪問與http:// localhost/index.html'相同的機器。這是一個獨立的臺式機。 –

+0

如果你仍然遇到這個問題,你會發布Apache錯誤日誌嗎?另外,當你訪問'/ index.php'時,它是否會在文件中添加一個條目:'/ var/log/apache2/access_logs'? – krowe

回答

1

嘗試使用這個:

<VirtualHost *:80> 
     DocumentRoot /home/yair/code/business/public_html 

     <Directory /home/yair/code/business/public_html/> 
       Options Indexes FollowSymLinks MultiViews 
       AllowOverride All 
       Order allow,deny 
       allow from all 
     </Directory> 


     <Directory /> 
       AllowOverride None 
       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 

</VirtualHost> 
+0

它不起作用相同的錯誤 –

+0

@ Yair.R我更新了這個不使用命名的虛擬主機。我認爲這不適用於本地主機。 – krowe

+0

謝謝。有了這個配置,Apache從'/ var/www /'提供文件,而不是從'/ home/yair/code/business/public_html /'提供文件。我爲字符串'/ var/www /''grepped'/ etc/apache2',但唯一出現的地方是在''這一行的'apache2.conf'中, *指令*用於該目錄,但實際上並沒有配置Apache從該目錄提供服務。 –