doubiao7410 2013-08-31 14:29
浏览 22

Magento / Nginx - 子目录多线程

I have been looking through so many articles on this but nothing is helping!

I have installed a vanilla magento instance on Redhat with Nginx. The base store is working as expected but when I try to run a separate website which is configured using a sub directory "/privatesales".

my nginx/conf.d/sitename.conf contains:

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;
}
}

I have tried the following methods to get this to work:

1 - Adding switch function in index.php

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

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

2 - Adding the following into nginx config (conf/vanillamagento_rewrites.conf) and then symlinking the /privatesales directory to the webroot

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;
 }

Just not having much luck and have been trying to fix this for 2 days :P. Thanks!

  • 写回答

1条回答 默认 最新

  • douhan8430 2013-09-07 11:09
    关注

    got it working finally! You have to modify the URL after switching! Add the following to your index.php:

    $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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大