Используйте HHVM только для определенных URL-адресов

Я использую Magento на NGINX и HHVM 3.8 с откатом к PHP 5.5.9 на случай ошибок. Есть определенные дружественные URL-адреса, которые я всегда хотел бы обрабатывать с помощью резервного варианта.

Итак, я ищу ситуацию, когда url http://example.com/checkout/step2 и http://example.com/customer/ обрабатывается PHP-FPM, а все остальные URL-адреса одного и того же домен HHVM.

Как мне настроить эти URL-адреса в моей конфигурации nginx?

Вот как выглядит мой конфиг nginx:

 server {
   listen 80;
   server_name example.com;
   root /usr/local/www/example.com;

   charset utf-8;
   location / {
        index index.html index.php; ## Allow a static html file to be shown first
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d; ## Assume all files are cachable
        if ($request_uri ~* "\.(png|gif|jpg|jpeg|css|js|swf|ico|txt|xml|bmp|pdf|doc|docx|ppt|pptx|zip)$"){
             expires max;
        }
   }

   location  /. { ## Disable .htaccess and other hidden files
       return 404;
  }

  location @handler { ## Magento uses a common front handler
    rewrite / /index.php;
  }

  location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
    rewrite ^(.*.php)/ $1 last;
  }

  location ~ \.(hh|php)$ {
            proxy_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_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
            fastcgi_param  MAGE_RUN_TYPE store;

            fastcgi_pass    127.0.0.1:8001;
    }

    location @fallback {
            if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
            expires        off; ## Do not cache dynamic content
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_read_timeout 900s; # 15 minutes
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
            fastcgi_param  MAGE_RUN_TYPE store;
            include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }

    include conf/h5bp.conf;
    }

person nicemister    schedule 22.07.2015    source источник


Ответы (1)


Если я вас правильно понимаю, вы можете указать location с regexp, чтобы он соответствовал вашему URL-адресу, и внутри этого блока использовать обработку php-fpm:

server {
    listen 80;
    server_name example.com;
    ...
    location ~ example\.com/(checkout/step2|customer/).*\.php/ {
        ...
    }

    location / {
        ...
    }
    ...
}

http://nginx.org/en/docs/http/ngx_http_core_module.html#location

person Community    schedule 22.07.2015
comment
Я ищу ситуацию, когда URL example.com/checkout/step2 и example.com/customer обрабатывается PHP-FPM, а все остальные URL-адреса того же домена — HHVM. Я обновил свой вопрос с этим. - person nicemister; 22.07.2015
comment
Вы можете использовать регулярные выражения в server_name для соответствия вашим URL-адресам, см. ссылку выше. - person starikovs; 22.07.2015