2013-10-01 59 views
2

我嘗試在同一個VPS上使用HHVM提供頁面來託管多個域。HHVM爲多個域提供服務

我想知道如何編寫VirtualHost以便在我的/ var/www目錄中指向正確的文件夾?

例如xxx.domain.com >> /var/www/domain.com/

回答

2

好消息。自HHVM 2.3(2013年12月13日)發佈以來,您可以在FCGI模式下運行HHVM。使用Nginx或Apache,它的工作非常好。

參考:http://www.hhvm.com/blog/1817/fastercgi-with-hhvm

使用舊版本HHVM的,你可以在內部端口上運行多個服務器實例,即8001,8002,等等。然後配置Nginx的反向代理。 (Apache也可以這樣做)。

upstream node1{ 
    server 127.0.0.1:8001; 
} 

upstream node2{ 
    server 127.0.0.1:8002; 
} 
server { 
    ... 
    server_name server1.com; 
     location ~ \.php$ { 
     proxy_pass http://node1; 
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; 
      proxy_redirect off; 
      proxy_buffering off; 
      proxy_set_header  Host   $host; 
      proxy_set_header  X-Real-IP  $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Forwarded-Ssl on; #only for https 
    } 
} 

server { 
    ... 
    server_name server2.com; 
     location ~ \.php$ { 
     proxy_pass http://node2; 
     proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; 
      proxy_redirect off; 
      proxy_buffering off; 
      proxy_set_header  Host   $host; 
      proxy_set_header  X-Real-IP  $remote_addr; 
      proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-Forwarded-Ssl on; #only for https 
    } 
} 

當然這個設置佔用大量內存。如果可以升級,請使用2.3。

1

顯然是沒有可能的。根據代碼託管的官方github repository存在open issue關於您詢問的同一問題,它的標籤爲願望清單/功能請求

解決此問題的最好方法可能是爲每個域運行HHVM服務器(意味着每個域需要不同的根文件夾)並使用Apache或Nginx作爲代理。

0

在Nginx的,我能得到這個工作的唯一方法是使用/SourceRoot爲HHVM,並在我的/etc/nginx/hhvm.conf文件中添加一個fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;/。有了這樣的組合,到目前爲止,我運行了大約7個站點。我正在運行Ubuntu 13.10 64位。

/etc/hhvm/server.hdf,改變SourceRoot = /var/wwwSourceRoot = /

Server { 
    Port = 9000 
    SourceRoot =/
    DefaultDocument = index.php 
} 

/etc/nginx/hhvm.conf,添加/在前面的$document_root$fastcgi_script_name;

location ~ \.php$ { 
    fastcgi_split_path_info ^(.+?\.php)(/.*)$; 
    fastcgi_keep_conn on; 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name; 
    fastcgi_intercept_errors on; 
    fastcgi_read_timeout 300; 
    include  fastcgi_params; 
} 

您可能還需要改變fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;,至少我不得不與我的。

使用/作爲您的SourceRoot可能會產生安全隱患 - 我通過防火牆端口9000儘可能減輕此限制,以便只有本地主機才能訪問它。或者你也可以使用套接字。不是傻瓜,但從我迄今看到的情況來看,這沒什麼。

相關問題