2015-10-02 73 views
3

我正在與HHVM上nginx的PHP應用程序爲主要和PHP-FPM作爲備份HHVM退回到PHP-FPM

這是我關於PHP處理

location ~ \.(hh|php)$ { 
    fastcgi_intercept_errors on; 
    error_page 500 501 502 503 = @fallback; 

    try_files $uri =404; 

    fastcgi_split_path_info ^(.+\.php)(/.+)$; 

    fastcgi_keep_conn on; 

    include   fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param SERVER_NAME $host; 
    fastcgi_pass 127.0.0.1:9000; 
    } 

    location @fallback { 

    try_files $uri =404; 

    fastcgi_split_path_info ^(.+\.php)(/.+)$; 

    include   fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param SERVER_NAME $host; 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 

    } 

爲了測試Nginx的配置的配置,我停止了HHVM service.Normally,將請求傳遞給PHP-FPM,而應返回200,但我得到502錯誤如下:

12296#0: *17 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.34.235, server: stylep3.com, request: "GET/HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host:localhost 

難道我做錯了什麼在這裏

回答

5

這是可行的更簡單的方法。

首先用hhvm和php-fpm定義一個上游作爲備份。

upstream fastcgi_server { 
    server unix:/var/run/hhvm/hhvm.sock; 
    server unix:/var/run/php-fpm-mysite.sock backup; 
} 

就用fastcgi_server好像是唯一的後端,與故障轉移工作nginx的交易,而不是你。

fastcgi_pass fastcgi_server; 

模塊上游文檔非常有啓發性。

http://nginx.org/en/docs/http/ngx_http_upstream_module.html

彙總,你的榜樣應該是這樣的:

upstream php_backend { 
    server 127.0.0.1:9000; 
    server unix:/var/run/php5-fpm.sock backup; 
} 


server { 
# 
# other conf... 
# 

location ~ \.(hh|php)$ { 
    fastcgi_intercept_errors on; 

    try_files $uri =404; 

    fastcgi_split_path_info ^(.+\.php)(/.+)$; 

    fastcgi_keep_conn on; 

    include   fastcgi_params; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    fastcgi_param SERVER_NAME $host; 
    fastcgi_pass php_backend; 
    } 

} 
+0

其實,我想這一個too.I知道我寫的是多餘的,但由於此配置沒有工作,我寫的以這種方式進行配置,但即使這樣也會引發錯誤。 – 5ud0

+0

我發現它, 顯然,根據官方指示,我在nginx虛擬主機中包含了hhvm.conf,似乎覆蓋了php-fpm並嘗試連接它! 刪除它解決了問題 – 5ud0

+0

@ 5ud0我有生產服務器運行這個配置,它的工作完美 –