仅对某些网址

时间:2015-07-22 08:26:24

标签: php magento nginx url-rewriting hhvm

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

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

如何在我的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;
    }

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您可以使用regexp指定location以匹配您的网址,并在此区域内使用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