magento 与 nginx 前端和 REST API url

magento 与 nginx 前端和 REST API url

我们已经使用 nginx 配置了 magento,我们尝试使用 http//magentohost/api/rest 来管理客户,但是当我们尝试访问该 url 时出现 404。

只是想知道有人用 nginx 正确配置了 magento REST api url

我们的配置

server {
  listen 80;
  server_name store.magentohost.com;
  access_log /var/log/nginx/store.magentohost.com.access.log;
  error_log  /var/log/nginx/store.magentohost.com.error.log;

  root /home/store/public_html;

  location / {
    index    index.php index.html index.htm;
    try_files $uri $uri/ @handler; ## if missing pass the URI to magento's front handler
    expires 30d; ## assume all files are cachable
  }

  ## These locations would be hidden by .htaccess normally
  location /app/                { deny all; }
  location /includes/           { deny all; }
  location /lib/                { deny all; }
  location /media/downloadable/ { deny all; }
  location /pkginfo/            { deny all; }
  location /report/config.xml   { deny all; }
  location /var/                { deny all; }

  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 ~ \.php$ {
    if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
    expires        off; ## Do not cache dynamic content 
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    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;
  }

  location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           36d;
  }
  location ~ /\.ht {
    deny all;
  }
  location ~ /\.hg {
    deny all;
  }

  location /nginx_status {
     stub_status on;
     access_log   off;
     allow ip;
     deny all;
    }


}

答案1

相对于您的 Magento 应用程序,编辑您的 Nginx 配置,通过为 API 请求添加位置处理程序,如下所示:

location /api {
    rewrite ^/api/(\w+).*$ /api.php?type=$1 last;
}

来源:https://gist.github.com/mklooss/7300787#gistcomment-1245474

答案2

添加api配置。

location /api {
    rewrite ^/api/rest /api.php?type=rest last;
    rewrite ^/api/v2_soap /api.php?type=v2_soap last;
    rewrite ^/api/soap /api.php?type=soap last;
}

相关内容