首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento / Nginx -子目录multistore

Magento / Nginx -子目录multistore
EN

Stack Overflow用户
提问于 2013-08-31 22:29:52
回答 1查看 1.8K关注 0票数 0

我已经看了这么多关于这方面的文章,但都没有什么帮助!

我已经在Redhat和Nginx上安装了一个vanilla magento实例。基本存储区工作正常,但当我尝试运行一个单独的网站时,该网站是使用子目录"/privatesales“配置的。

我的nginx/conf.d/sitename.conf包含:

代码语言:javascript
复制
server {
listen 192.168.01; ##changed for security
listen 80;
listen 443 ssl;

ssl_certificate     /etc/nginx/certs/server.crt;
ssl_certificate_key /etc/nginx/certs/server.key;
ssl_session_timeout 7m;
## Specify your SSL options here
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;

access_log /var/log/nginx/vanillamagento.local-access.log;
error_log  /var/log/nginx/vanillamagento.local-error.log;

server_name vanilla.domain.com;
root /var/www/vanillamagento/magento;
include conf/vanillamagento_rewrites.conf;
include conf/vanillamagento_security.conf;

# PHP handler
location ~ \.php {
  ## Catch 404s that try_files miss
  if (!-e $request_filename) { rewrite / /index.php last; }

  ## Store code is defined in administration > Configuration > Manage Stores
##  fastcgi_param MAGE_RUN_CODE default;
 ## fastcgi_param MAGE_RUN_TYPE store;

  # By default, only handle fcgi without caching
  include conf/magento_fcgi.conf;
}

# 404s are handled by front controller
location @magefc {
  rewrite / /index.php;
}

# Last path match hands to magento or sets global cache-control
location / {
  ## Maintenance page overrides front controller
  index index.html index.php;
  try_files $uri $uri/ @magefc;
  expires 24h;
}
}

我尝试了以下方法来实现这个功能:

1-在index.php中添加交换机功能

代码语言:javascript
复制
$host = explode(':', $_SERVER['HTTP_HOST']);
switch ($host[0]) {
case 'vanilla.domain.com/privatesales':
  $store = 'private';
  $type = 'website';
  break;

default:
  $store = 'base';
  $type = 'store';
}

2-将以下内容添加到nginx配置中(conf/vanillamagento_rewrites.conf),然后将/privatesales目录符号链接到webroot

代码语言:javascript
复制
location ~* \.php$ {
if (!-e $request_filename) {
    rewrite / /index.php last;
}
expires off;
set $runcode default;
set $runtype store;
if ( $request_uri ~* ^/privatesales) {
        set $runcode private;
        set $runtype website;
}
fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE $runcode;
fastcgi_param MAGE_RUN_TYPE $runtype;
include fastcgi_params;
 }

只是没有太多的运气,已经尝试了2天来解决这个问题:P。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2013-09-07 19:09:39

终于让它工作了!切换后需要修改URL!将以下内容添加到您的index.php:

代码语言:javascript
复制
$host = explode("/",$_SERVER['REQUEST_URI']);

//print_r($host); die();
switch ($host[1]) {
case 'privatesales':
$_SERVER['REQUEST_URI']=str_replace("/privatesales","",$_SERVER['REQUEST_URI']);
$mageRunCode  = "privatesales";
$mageRunType = "store";
 //$store = 'privatesales';
 //$type = 'website';
 break;

default:
$mageRunCode = 'default';
$mageRunType = 'store';
break;
}
Mage::run($mageRunCode, $mageRunType);
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18549235

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档