【问题标题】:Use HHVM only for certain urls仅对某些 url 使用 HHVM
【发布时间】:2015-10-12 00:17:20
【问题描述】:

我在 NGINX 和 HHVM 3.8 上运行 Magento,并在出现错误时回退到 PHP 5.5.9。有一些友好的 url 我总是想处理后备。

所以我正在寻找的是一种情况,即 url http://example.com/checkout/step2http://example.com/customer/ 由 PHP-FPM 处理,而同一域的所有其他 url 由 HHVM 处理。

如何在我的 nginx 配置中配置这些 url?

这是我的 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;
    }

【问题讨论】:

    标签: php magento nginx url-rewriting hhvm


    【解决方案1】:

    如果我理解正确,您可以使用正则表达式指定 location 以匹配您的 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

    【讨论】:

    • 我正在寻找的是 url example.com/checkout/step2example.com/customer 由 PHP-FPM 处理,而同一域的所有其他 url 由 HHVM 处理的情况。我已经用这个更新了我的问题。
    • 您可以在 server_name 中使用正则表达式来匹配您的 url,请参见上面的链接。
    猜你喜欢
    • 1970-01-01
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-30
    相关资源
    最近更新 更多