【问题标题】:Run HHVM and PHP simultaneously with Nginx使用 Nginx 同时运行 HHVM 和 PHP
【发布时间】:2015-04-06 18:17:57
【问题描述】:

我一直在使用 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;
}

失败的解决方案 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;
}

【问题讨论】:

    标签: php magento nginx hhvm


    【解决方案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;
        }
    }
    

    【讨论】:

    • 谢谢!!这确实起到了作用。我唯一的问题是我的位置理想情况下需要正则表达式,而location / 似乎总是在此之前排在第一位。除此之外,它工作得很好。我还在\php$ 位置使用fastcgi_keep_conn on;,因为这似乎是HHVM 所必需的。目前没有冲突
    猜你喜欢
    • 2015-06-10
    • 1970-01-01
    • 2014-07-15
    • 2017-12-16
    • 2023-03-16
    • 1970-01-01
    • 2017-12-15
    • 2015-07-20
    • 1970-01-01
    相关资源
    最近更新 更多