Magento的。 Nginx的。多店。如何将“index.php”添加到网址

时间:2015-04-16 12:27:21

标签: php magento nginx url-rewriting multistore

我下载了3个商店的magento并试图在localhost上安装它。

  • Ubuntu 14
  • Nginx的
  • Mysql的
  • PHP-FPM

    /app
    /downloader
    /includes
    ...
    /store1/index.php
    /store2/index.php
    

在我的store1/index.php内,我放了$mageRunCode = 'my_store_code'

当我打开网址http://mysite.local.dev/store1/时,所有内容都正常打开,但所有链接都不包含“index.php”,如果没有,则所有网址都不会打开。

返回404:

  

http://mysite.local.dev/store1/some-cms-page.html

开口良好:

  

http://mysite.local.dev/store1/index.php/some-cms-page.html

请您告诉我如何将网址重写为“index.php”添加到我的网址,或者请建议另一个更明确的解决方案。

提前致谢

server {

    listen 80;
    server_name local.dev *.local.dev;
    root /var/www/local.dev/www/$subdomain;
    set $subdomain "";
    if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
        set $subdomain $1;
    }
    if ($host ~* ^www.local.dev$) {
        set $subdomain "";
    }

    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
    }

    ## 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 /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

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

    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$ { ## Execute PHP scripts
        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 600; 
        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
    }

}

根据Emi的解决方案。

如果我清楚地了解你 - 这里是更新配置:

server {

    listen 80;
    server_name local.dev *.local.dev;
    root /var/www/local.dev/www/$subdomain;
    set $subdomain "";
    set $magento_run_code "";
    if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
        set $subdomain $1;
        set $magento_run_code $1;
    }
    if ($host ~* ^www.local.dev$) {
        set $subdomain "";
        set $magento_run_code "";
    }

    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
    }

    ## 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 /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }

    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }

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

    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$ { ## Execute PHP scripts
        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 600; 
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  MAGE_RUN_CODE $magento_run_code; ## Store code is defined in administration > Configuration > Manage Stores
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }

}

在我的core_store表中,我有以下内容(名称被替换):

default - sitename
default_store1 - store1
default_store2 - store2

不安全的网址是:

http://sitename.local.dev/
http://sitename.local.dev/store1/
http://sitename.local.dev/store2/

当我尝试打开 sitename.local.dev 时,尝试使用 $ mage_run_code = sitename 打开。那是因为我得到404.我认为预期值应该是默认

store1的网址应该是多少? sitename.local.dev/store1?

upd.1 我理解你的想法。

我们什么时候

    if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
        set $subdomain $1;
        set $magento_run_code $1;
    }

magento开始执行$ 1,等于第三域lvl中的值。就我而言http://sitename.local.dev - 它是网站名称

我把它改成了

    if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
        set $subdomain $1;
        set $magento_run_code default;
    }

现在它适用于第一家商店。

让我们为store1

应用您的解决方案

根据这个解决方案,我目前的问题是:

  

目录:{magento_root} / store1 / *

     

mage_run_code:default_store1

     

url:http://store1.local.devhttp://sitename.local.dev/store1/ ??????

     

nginx配置:据我所知,它将取决于网址。我应该使用哪个url和哪个配置?

1 个答案:

答案 0 :(得分:0)

如果您想使用3个不同的商店运行Magento,为什么不使用默认设置? 默认的意思是,您在nginx配置中设置了一些变量,具体取决于您的主机,在您的情况下,您可以使用类似$ subdomain的内容:

set $magento_run_code ""; #default value
if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
    set $subdomain $1;
    set $magento_run_code $1;
}
if ($host ~* ^www.local.dev$) {
    set $subdomain "";
    set $magento_run_code "";
}

然后在位置下你必须设置:

fastcgi_param  MAGE_RUN_CODE $magento_run_code;

必须从您的管理员(系统>管理商店)定义值,否则Magento将无法加载该商店。

同样使用index.php可以从系统>中的管理员调整。配置> GENERAL Web>搜索引擎优化

有关加载的商店代码的更多信息,请检查index.php中的以下行:

$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';