2015-09-04 33 views
2

我有這樣的Apache虛擬主機定義:怪異的行爲:請求超過了10個內部重定向的上限,由於可能配置錯誤

<VirtualHost *:80> 
    ServerName server1.qa.com 
    ServerAlias server2.qa.com 
    ServerAlias server3.qa.com 

    DirectoryIndex app_dev.php 

    DocumentRoot /var/www/html/web 
    <Directory /var/www/html/web> 
     # enable the .htaccess rewrites 
     AllowOverride All 
     Order allow,deny 
     Allow from All 
    </Directory> 

    ErrorLog /var/log/httpd/error.log 

    LogFormat "%h %l %t \"%r\" \"%{X-PDONE-SESSION-ID}i\" %>s %b" common 
    CustomLog /var/log/httpd/access.log common 
</VirtualHost> 

如果我打電話http://server1.qa.comapp_dev.php我這個錯誤結束:

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

如果我打電話http://server1.qa.com/app_dev.php一切都很好,應用程序的作品。哪裏有問題?這是一個Symfony 2.7項目,我正在嘗試爲該路徑設置DirectoryIndex,有何建議?

這是.htaccess定義:

DirectoryIndex app.php 

<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 

    RewriteCond %{HTTP:Authorization} . 
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 

    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 

    RewriteRule .? %{ENV:BASE}/app.php [L] 
</IfModule> 

的access.log

有沒有什麼奇怪的access.log或有幫助的,如下面的線看到:

// called server1.qa.com 

[04/Sep/2015:12:25:09 -0400] "GET/HTTP/1.1" 500 618 

// called server1.qa.com/app_dev.php 
[04/Sep/2015:12:25:14 -0400] "GET /app_dev.php HTTP/1.1" 302 340 
[04/Sep/2015:12:25:14 -0400] "GET /app_dev.php/admin/login HTTP/1.1" 302 416 
[04/Sep/2015:12:25:15 -0400] "GET /app_dev.php/login HTTP/1.1" 200 21521 
[04/Sep/2015:12:25:16 -0400] "GET /app_dev.php/_wdt/c84bab HTTP/1.1" 200 40961 

回答

0

好了,我已經找到了解決我的問題,也許沒有最好的一個或容易,但通過Christian Flothmann在這裏推薦這個comment。 Apache的虛擬主機定義如下圖所示:

<VirtualHost *:80> 
    ServerName server1.com 
    ServerAlias server2.com 
    ServerAlias server3.com 

    DocumentRoot /var/www/html/web 

    # if we're setting up production environment 
    # DirectoryIndex app.php 

    # if we're setting up development or qa environment 
    # DirectoryIndex app_dev.php 

    <Directory /var/www/html/web> 
     AllowOverride None #important rule, do not allow any .htaccess 
     Order allow,deny 
     Allow from All 

     RewriteEngine On 
     RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
     RewriteRule ^(.*) - [E=BASE:%1] 

     RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

     RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
     RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 

     RewriteCond %{REQUEST_FILENAME} -f 
     RewriteRule .? - [L] 

     # if we're setting up production environment 
     # RewriteRule .? %{ENV:BASE}/app.php [L] 

     # if we're setting up development or qa environment 
     # RewriteRule .? %{ENV:BASE}/app_dev.php [L] 
    </Directory> 

    ErrorLog /var/log/httpd/error.log 

    LogFormat "%h %l %t \"%r\" %>s %b" common 
    CustomLog /var/log/httpd/access.log common 
</VirtualHost> 

Note: It is important to read reviews, some rules must be applied depending on the environment that we will configure that means comments at begin of the line should be removed for properly functioning of Apache and application itself.

0

好,我會再試一次。

我認爲這將是更容易有兩個.htaccess文件,一個在任何環境:

  • 從您的虛擬主機文件中刪除的DirectoryIndex
  • 複製你的.htaccess到.htaccess_dev
  • 替換.htaccess_dev所有「app.php」爲「app_dev.php」
  • 在您的虛擬主機中添加「AccessFileName .htaccess_dev」並重新啓動您的apache。

現在,您的.htaccess_dev將被使用,它不應該碰到你的app.php文件。

+0

你有沒有手動刪除這些行?我通過運行'symfony new temp_project'創建了一個新項目,創建的'.htaccess'文件有這兩行,我不認爲這也是這些行上面的註釋問題'#設置HTTP_AUTHORIZATION標頭被刪除apache' – ReynierPM

+0

不,我沒有手動刪除它們。我的項目最初是用Symfony 2.3構建的,我升級到2.7,它從來沒有這些線。如果你看看https://github.com/symfony/symfony-demo/blob/master/web/.htaccess,這些行不在那裏。 – RaulFerriz

+0

嗯,新的Symfony 2.7添加這些默認情況下,我不知道他們是什麼,或者如果我可以輕鬆地騎他們,出於某種原因Symfony團隊應該添加他們 – ReynierPM

0

你有你的虛擬主機設置,以便app_dev.php是索引,但在你的htaccess文件中,它使用app.php。試着改變使用app_dev.php代替:

# don't really need this, it's in your vhost 
#DirectoryIndex app_dev.php 

<IfModule mod_negotiation.c> 
    Options -MultiViews 
</IfModule> 

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ 
    RewriteRule ^(.*) - [E=BASE:%1] 

    RewriteCond %{HTTP:Authorization} . 
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 

    RewriteCond %{ENV:REDIRECT_STATUS} ^$ 
    RewriteRule ^app_dev\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L] 

    RewriteCond %{REQUEST_FILENAME} -f 
    RewriteRule .? - [L] 

    RewriteRule .? %{ENV:BASE}/app_dev.php [L] 
</IfModule> 
+0

不,也沒有解決這個問題,我試過了,仍然是同樣的問題 – ReynierPM

相關問題