与Nginx同时运行HHVM和PHP

时间:2015-04-01 13:43:39

标签: php magento nginx hhvm

我一直在使用HHVM和Nginx运行magento站点。到目前为止,我没有遇到任何问题,我得到的是一个非常受欢迎的显着性能提升。

但是,我刚刚添加了一个使用HHVM不支持的PHP函数的插件。好消息是这个插件只需要一页。坏消息是我没有将Nginx配置为仅使用PHP来提供此页面。

某些使用错误指令的人使用的常用后备技巧在这种情况下不起作用,因为页面不会引发错误。如果启用HHVM,它就不起作用。

相反,我试图为该特定页面编写许多位置块的变体。没有工作,这些是我认为可以做到的两个。

有没有办法只针对特定页面运行PHP?

失败的解决方案1 ​​

location  ~ /page/.+\.php${

    if (!-e $request_filename) { rewrite / /index.php last; }
    fastcgi_pass   unix:/var/run/php5-fpm.sock; ##Unix socket
    fastcgi_param  HTTPS $fastcgi_https;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;      
}

location ~ \.(hh|php)$ {

    if (!-e $request_filename) { rewrite / /index.php last; }
    fastcgi_keep_conn on;
    fastcgi_pass unix:/var/run/hhvm/sock;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS $fastcgi_https;
    include        fastcgi_params;
}

FAILED SOLUTION 2(带嵌套位置)

location ~ /page/ {

    location ~ .php$ {
        if (!-e $request_filename) { rewrite / /index.php last; }
        fastcgi_pass   unix:/var/run/php5-fpm.sock; ##Unix socket
        fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;

    }
}

location ~ \.(hh|php)$ {

    if (!-e $request_filename) { rewrite / /index.php last; }
    fastcgi_keep_conn on;
    fastcgi_pass unix:/var/run/hhvm/sock;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param  HTTPS $fastcgi_https;
    include        fastcgi_params;
}

1 个答案:

答案 0 :(得分:1)

尝试使用可变条件方法,它适用于我,以/serve-with-php/开头的地点与unix:/var/run/php5-fpm.sock一起提供,而所有其他地方都使用127.0.0.1:9000

server {
    root /home/vearutop/test-hhvm;
    index index.php index.html index.htm;
    error_log /var/log/nginx-error.log error;
    charset        utf-8;

    server_name test-hhvm;

    location / {
        set $fcgi_worker 127.0.0.1:9000; # hhvm handle
        try_files $uri $uri/ /index.php?$query_string;
    }


    location /serve-with-php/ {
        set $fcgi_worker unix:/var/run/php5-fpm.sock; # php-fpm handle
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass $fcgi_worker;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}