【发布时间】:2015-06-22 20:37:24
【问题描述】:
我用 3 个商店下载了 magento,并尝试将其安装在本地主机上。
- Ubuntu 14
- Nginx
- Mysql
-
php-fpm
/app /downloader /includes ... /store1/index.php /store2/index.php
在我的store1/index.php 里面我放了$mageRunCode = 'my_store_code'
当我打开 url http://mysite.local.dev/store1/ 时,一切都可以正常打开,但所有链接都不包含 'index.php',否则所有 url 都不会打开。
返回 404:
开得好:
您能否告诉我如何重写网址以将“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。我认为预期值应该是 default。
store1 的 url 应该是什么?站点名称.local.dev/store1 ?
更新.1 我理解你的想法。
当我们有
if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
set $subdomain $1;
set $magento_run_code $1;
}
magento 以 $1 开始执行,它等于第三个域 lvl 中的值。在我的情况下 http://sitename.local.dev - 它是 sitename。
我改成
if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
set $subdomain $1;
set $magento_run_code default;
}
现在它适用于第一家商店。
让我们为 store1 应用您的解决方案
根据这个解决方案,我目前的问题是:
目录:{magento_root}/store1/*
mage_run_code: default_store1
网址:http://store1.local.dev 或 http://sitename.local.dev/store1/ ??????
nginx 配置:据我所知,它将取决于 url。我应该使用哪个 url 和哪个配置?
【问题讨论】:
标签: php magento nginx url-rewriting multistore