我用 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'
当我打开 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 的网址应该是什么?站点名称.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 - 它是sitename。
我把它改成
if ($host ~* ^([a-z0-9-\.]+)\.local.dev$) {
set $subdomain $1;
set $magento_run_code default;
}
现在它适用于第一家商店。
让我们将您的解决方案应用于 store1
根据这个解决方案,我目前的问题是:
目录:{magento_root}/store1/*
法师运行代码:default_store1
网址:http ://store1.local.dev或http://sitename.local.dev/store1/ ??????
nginx 配置:据我所知,它将取决于 url。我应该使用哪个 url 和哪个配置?