Apache 2.4 HHVM 3.1 靜態內容服務

Apache 2.4 HHVM 3.1 靜態內容服務

我已經在ubuntu 13.10 上使用HHVM 3.1.0(每晚)設定了apache 2.4 由於某種原因,伺服器正確地提供了hhvm 檔案(.php),但是當我嘗試載入.html/.css 或任何其他靜態文件時,它啟動下載而不是顯示

我在 stackoverflow 上問了這個問題,但它被擱置了,因為它與伺服器相關:原帖

我的 HHVM server.ini 如下圖:

hhvm.server.port = 9000
hhvm.server.type = fastcgi
hhvm.server.default_document = index.php
hhvm.server.source_root = /var/www

hhvm.enable_static_content_from_disk = true

並且 apache2.conf 包含以下 proxypassmatch:

ProxyPassMatch ^/(.*.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1

有什麼建議嗎?

答案1

ProxyPassMatch 指令用於僅將某些流量(即對 php 檔案的請求)路由到 FastCGI 伺服器(即 HHVM)。請改用 ProxyPass 指令:

ProxyPass / fcgi://127.0.0.1:9000/var/www/whatever.com/

根據文件,這應該將所有請求路由到 FastCGI 伺服器。

編輯:好的,為了回應您的評論,ProxyPassMatch 是您要使用的指令。

我不會與您反复討論如何設置所有內容,而是僅解釋一下我如何在 Ubuntu 12.04 上進行設置,也許您可以找出您缺少的內容。

首先,即使我正在運行 HHVM v3.1.0-dev,我仍然使用舊的 .hdf 配置格式,因為我似乎無法讓訪問日誌以新的 .ini 格式工作。我嘗試過hhvm.log.access.file = /var/log/hhvm/access.log,但沒有成功。這是故障排除的重要日誌,因此我現在將繼續使用 .hdf。

這是我的新貴腳本:

description "HipHop VM server"

start on filesystem or runlevel [2345]
stop on runlevel [!2345]

respawn
respawn limit 10 5
umask 002

pre-start script
    mkdir -p -m0755 /var/run/hhvm
    chown apachetwo:threews /var/run/hhvm
end script

# Location of executable
env SERVER=/usr/local/sbin/hhvm

exec $SERVER --mode daemon -c /etc/hhvm/test.hdf --user apachetwo

每當我想停止和啟動 HHVM 時,我都會使用sudo stop hhvmsudo start hhvm

這是我的 /etc/hhvm/server.hdf 檔案:

PidFile = /var/run/hhvm/pid

Server {
  Type = fastcgi
  Port = 9000
  SourceRoot = /var/www/html/
  DefaultDocument = index.php
}

Log {
  Level = Verbose
  AlwaysLogUnhandledExceptions = true
  RuntimeErrorReportingLevel = 8191
  UseLogFile = true
  UseSyslog = false
  File = /var/log/hhvm/error.log
  Access {
    * {
      File = /var/log/hhvm/access.log
      Format = %h %l %u % t \”%r\” %>s %b
    }
  }
}

Repo {
  Central {
    Path = /var/log/hhvm/.hhvm.hhbc
  }
}

MySQL {
  TypedResults = false
}

理論上,新格式的等效設定檔.ini將如下所示:

; php options
pid = /var/run/hhvm/pid

; hhvm specific
hhvm.server.type = fastcgi
hhvm.server.port = 9000
hhvm.server.source_root = /var/www/html
hhvm.server.default_document = index.php

hhvm.log.level = Verbose
hhvm.log.always_log_unhandled_exceptions = true
hhvm.log.runtime_error_reporting_level = 8191
hhvm.log.use_log_file = true
hhvm.log.use_syslog = false
hhvm.log.file = /var/log/hhvm/error.log
hhvm.log.access.file = /var/log/hhvm/access.log
hhvm.log.access.format = %h %l %u % t \”%r\” %>s %b

hhvm.repo.central.path = /var/log/hhvm/.hhvm.hhbc
hhvm.mysql.typed_results = false

而且,這裡有一個基於我的網站之一的 VirtualHost 檔案範例,該檔案配置為將 PHP 腳本的請求代理到 HHVM。這恰好適用於透過 mod_rewrite 提供乾淨 URL 的 Laravel 4.2.x 網站。如果您的網站也配置了乾淨的 URL,請確保[PT]在該行的末尾配置了RewriteRule該 URL,以便 mod_rewrite 在完成請求後將請求傳遞給 mod_proxy。最初,我正在使用[L](可能是錯誤的)並且無法弄清楚為什麼 mod_proxy 沒有將請求傳遞給 HHVM。

<VirtualHost *:80>

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/site.com/htdocs/public/$1

    DirectorySlash On
    DirectoryIndex index.php

    ServerAdmin [email protected]
    ServerName www.site.com
    DocumentRoot /var/www/site.com/htdocs/public/

    AllowEncodedSlashes On

    # Don't display the ServerAdmin email address on server generated pages
    ServerSignature Off

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !^(index\.php|/images|/includes|/cache|/mpd|/packages|/queues|/samples|/robots\.txt|/sitemap\.xml)
    RewriteRule ^(.*)$ /index.php$1 [PT]

    <Directory /var/www/site.com/htdocs>
        Require all granted
        Options +FollowSymLinks
        AllowOverride None
    </Directory>

    <Directory /var/www/site.com/htdocs/public>
        Require all granted
        Options +FollowSymLinks
        AllowOverride None
    </Directory>

    ErrorLog /var/log/apache2/www.site.com.error.log

    LogLevel alert rewrite:trace6 proxy:trace6

    CustomLog /var/log/apache2/www.site.com.access.log combined

</VirtualHost>

我認為這些是您需要關注的三個主要配置文件。 ProxyPassMatch 指令應指示 Apache 將 PHP 檔案的請求代理到 HHVM。對其他文件類型的請求應由 Apache 正常處理。如果您可以註解掉 ProxyPassMatch 指令,重新啟動 Apache 並且一切正常,那麼我會感到驚訝。我猜你的 Apache 應該要提供 CSS、JS 和 HTML 檔案下載負責。

相關內容