Web 服务不适用于全新安装

Webservice doens't working on fresh install

执行 Prestashop ( v 1.6.0.9 ) 的全新安装后,我遇到了一些关于使网络服务功能可用的问题。

我已经设置了密钥,我可以使用 url 检查 ws 的可用性

http://example.com/webservice/dispatcher.php?ws_key=my_key

3 个相关结果是:

http://example.com/api/employees?schema=synopsis

http://example.com/api/employees

http://example.com/api/employees?schema=blank

所以,在测试上面的链接时,我收到消息 此页面不可用 就在我面前,我不确定为什么会这样。

有关其他信息,我按照 Web Service Tutorial 上的步骤将 PSWebServiceLibrary.php 文件下载到我的根文件夹中,我还创建了一个包含以下内容的测试文件:

<?php
/**
 * Created by PhpStorm.
 * User: thales.pereira
 * Date: 05/01/15
 * Time: 16:10
 */
require_once( './PSWebServiceLibrary.php' );

$shop_url="http://localhost";
$secret_key="the_key";
$debug=false;
try {
    $webService = new PrestaShopWebservice($shop_url, $secret_key, $debug);

    $opt['resource'] = 'customers?schema=synopsis';
    $xml = $webService->get($opt);
    echo $xml;
}
catch (PrestaShopWebserviceException $ex) {
    echo 'Other error: <br />' . $ex->getMessage();
}

但是……结果是:

Other error:
This call to PrestaShop Web Services failed and returned an HTTP status of 404.
That means: Not Found.

对于这个开发环境,我使用的是 MAMP 版本 3.0.7.3

主要问题出在 nginx 正则表达式规则上。

这是目前对我有用的:

server {

  listen 80;

  server_name 127.0.0.1;
  access_log   /var/log/nginx/prestashop.access.log;
  error_log    /var/log/nginx/prestashop.error.log;
  root /var/www/prestashop;

  if ($http_host != "127.0.0.1") {
    rewrite ^ http://127.0.0.1$request_uri permanent;
  }

  index index.php index.html;

  location = /favicon.ico {
    log_not_found off;
    access_log off;
  }

  location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
  }

  # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).

  location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
  }

  rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url= last;
  rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p//.jpg last;
  rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p///.jpg last;
  rewrite ^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p////.jpg last;
  rewrite ^/([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/////.jpg last;
  rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p//////.jpg last;
  rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p///////.jpg last;
  rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p////////.jpg last;
  rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/////////.jpg last;
  rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/.jpg last;
  rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/.jpg last;
  rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/. last;

  try_files $uri $uri/ /index.php$is_args$args;

  error_page 404 /index.php?controller=404;

  location ~* \.(gif)$ {
    expires 2592000s;
  }

  location ~* \.(jpeg|jpg)$ {
    expires 2592000s;
  }

  location ~* \.(png)$ {
    expires 2592000s;
  }

  location ~* \.(css)$ {
    expires 604800s;
  }

  location ~* \.(js|jsonp)$ {
    expires 604800s;
  }

  location ~* \.(js)$ {
    expires 604800s;
  }

  location ~* \.(ico)$ {
    expires 31536000s;
  }

  location ~ \.php$ {
    try_files $uri =404;
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors on;
  }

}