Reputation: 2877
I've been running a magento site using HHVM and Nginx. So far I hadn't experienced any problems and all I got was a very welcomed noticeable performance boost.
However, I've just added a plugin which uses PHP functions which are unsupported by HHVM. The good news is that this plugin is only needed for one page. Bad news is I'm not configuring Nginx right to serve this page only with PHP.
The usual fallback trick used by some people using error directives does not work in this case because the page doesn't throw an error. It just doesn't work if HHVM is enabled.
Instead, I've tried to write many variations of location blocks for that particular page. None worked, and these are the two that I had thought would do the trick.
Is there a way to run PHP only for a specific page?
FAILED SOLUTION 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 (with nested location)
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;
}
Upvotes: 2
Views: 538
Reputation: 4072
Try using variable condition approach, it works for me, locations starting with /serve-with-php/
are being served with unix:/var/run/php5-fpm.sock
, while all the others are being served with 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;
}
}
Upvotes: 1