马根托。Nginx。多商店。如何添加';php';到URL

马根托。Nginx。多商店。如何添加';php';到URL,php,magento,nginx,url-rewriting,multistore,Php,Magento,Nginx,Url Rewriting,Multistore,我下载了带有3个商店的magento,并试图在localhost上安装它 Ubuntu 14 Nginx Mysql php fpm /app /downloader /includes ... /store1/index.php /store2/index.php 在mystore1/index.php中,我放置了$mageRunCode='my\u store\u code' 当我打开urlhttp://mysite.local.dev/store1/所有内容都正常打开,但所有链接都

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

  • Ubuntu 14
  • Nginx
  • Mysql
  • php fpm

    /app
    /downloader
    /includes
    ...
    /store1/index.php
    /store2/index.php
    
在my
store1/index.php
中,我放置了
$mageRunCode='my\u store\u code'

当我打开url
http://mysite.local.dev/store1/
所有内容都正常打开,但所有链接都不包含“index.php”,没有它,所有URL都无法打开

返回404:

开井:

您能告诉我如何重新编写url以将'index.php'添加到我的url中吗,或者请建议另一个更清晰的解决方案

提前谢谢

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表中,我有以下内容(名称已替换):

不安全的URL包括:

http://sitename.local.dev/
http://sitename.local.dev/store1/
http://sitename.local.dev/store2/
当我试图打开sitename.local.dev时,它试图使用$mage\u run\u code=sitename打开。那是因为我得了404分。我认为预期值应该是默认值

store1的url应该是什么?sitename.local.dev/store1

upd.1 我理解你的想法

当我们

    if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
        set $subdomain $1;
        set $magento_run_code $1;
    }
magento以$1开始执行,该值等于第三个域lvl中的值。在我的例子中,它是sitename

我把它改成了

    if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
        set $subdomain $1;
        set $magento_run_code default;
    }
现在它在第一家商店很好用

让我们为store1应用您的解决方案

根据这个解决方案,我目前的问题是: 目录:{magento_root}/store1/*

图像运行代码:默认存储1

网址:或

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


如果您想在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将无法加载该存储

还可以在“系统>配置>常规Web>搜索引擎优化”中的管理中调整index.php

有关加载的存储代码的更多信息,请查看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';

更新了我的第一篇帖子,你检查了每个商店的不安全和安全的基本url了吗?这可以从“系统>配置>常规Web>不安全”更改。从左栏中,您可以更改当前配置范围,以匹配要为其设置基本url的商店-您必须为每个商店执行此操作。我添加了当前的nginx配置并写入了不安全的url。否,它返回404页。最可能的原因是它试图用代码='sitename'打开。但我的网站上没有这样的代码。只有default或default\u store1。那么,在您的nginx配置集中
设置$magento\u运行\u code“default\u store1”
,而不是像我说的$1,您可以从index.php中转储值,以查看magento试图从那里加载和调试的内容。
$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';