【问题标题】:Nginx + Magento in subfolderNginx + Magento 在子文件夹中
【发布时间】:2013-10-02 16:31:37
【问题描述】:

我在这里查看了相关主题,但没有为我解决问题。 所以这就是我正在做的事情。 我们目前正在从一台服务器转移到另一台服务器。旧的运行 Apache,新的运行 Nginx。因此,对于我们的一个网站,我们在http://mydomain.com 上有一个 Wordpress CMS 网站 和http://mydomain.com/shop上的 Magento 安装

CMS 运行正常。如果涉及到商店,我会被卡住。显示了 Magento index.php - 到目前为止一切都很好。但是,当我尝试在商店的其他地方导航时,我遇到了 404 错误。因此,重写时一定有一些错误。我尝试了很多方法都不起作用。

所以这是我当前的虚拟主机配置:

server {
listen               80;
listen              443;
server_name         www.domain.de domain.de *.domain.de;
root                /var/www/domain.de/www.domain.de/htdocs;
index       index.php;

access_log          /var/log/nginx/domain_access.log;
error_log           /var/log/nginx/domain_error.log;

error_page      403   /403.php;
error_page      404   /404.php;
error_page      500   /500.php;
error_page      501   /500.php;
error_page      502   /500.php;
error_page      503   /500.php;

location ~* \.(js|css|jpg|jpeg|gif|png|ico|swf)$ {
    if (-f $request_filename) {
      expires   30d;
      add_header Cache-Control "public";
      break;
    }
}

#Temp-Dateien blocken
location ~* \.(bak|cache|csv|git|old|php~|spool|svn|swp|temp|tmp)$ {
    deny all;
}

#Sonstige Dateien blocken
location ~* \.(1st|386|app|ani|asm|bat|bin|cfg|cmd|cnf|com|cpl|dbs|dll|drv|exe|inc|sh|lnk|reg|scr|sys|vxd)$ {
    deny all;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location /shop {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
}

location ~ ^/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /var/export/ { internal; }
location /. { return 404; }
location @handler { rewrite /shop/ /index.php; }
location ~* .php/ { rewrite ^(.*.php)/ www last; }

location ~ ^/(gpack|img|tmp/map)/ {
   allow      all;
}

location ~ .*\.php?$ {
    fastcgi_pass             unix:/var/run/php/domain.de.sock;
    fastcgi_index            index.php;
include                  conf/fastcgi.conf;
}
}

欢迎任何提示。我想这一定是我的一个小错误。

提前致谢。 问候, 史蒂文

【问题讨论】:

  • 我认为您需要在@handler = /var/www/domain.de/www.domain.de/htdocs/shop 中添加一个root
  • 我尝试像这样添加它:location @handler { root /var/www/domain.de/www.domain.de/htdocs/shop; } 而不是location @handler { rewrite /shop/ /index.php; },但没有成功。有什么建议吗?
  • 你需要root和rewrite,你都用了吗?

标签: magento nginx subdirectory


【解决方案1】:

* 编辑 *

好的,我解决了。 这是我当前的配置文件。

server {
listen               80;
listen              443;
server_name         www.domain.de domain.de *.domain.de;
root                /var/www/domain.de/www.domain.de/htdocs;
index       index.php;

access_log          /var/log/nginx/domain_access.log;
error_log           /var/log/nginx/domain_error.log;

error_page      403   /403.php;
error_page      404   /404.php;
error_page      500   /500.php;
error_page      501   /500.php;
error_page      502   /500.php;
error_page      503   /500.php;

location ~* \.(js|css|jpg|jpeg|gif|png|ico|swf)$ {
    if (-f $request_filename) {
      expires   30d;
      add_header Cache-Control "public";
      break;
    }
}


#Temp-Dateien blocken
location ~* \.(bak|cache|csv|git|old|php~|spool|svn|swp|temp|tmp)$ {
    deny all;
}

#Sonstige Dateien blocken
location ~* \.(1st|386|app|ani|asm|bat|bin|cfg|cmd|cnf|com|cpl|dbs|dll|drv|exe|inc|sh|lnk|reg|scr|sys|vxd)$ {
    deny all;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location /shop {
    index index.html index.php;
try_files $uri $uri/ @handler;
    expires 30d;
    if ($uri ~ "^/index.php/admin.*$"){
        rewrite ^/index.php/admin(.*) /admin$1 redirect;
    }
}

location ~ ^/shop/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /shop/var/export/ { internal; }
location @handler { rewrite / /shop/index.php; }

location ~ ^/(gpack|img|tmp/map)/ {
   allow      all;
}

location ~ .*\.php?$ {
    fastcgi_pass             unix:/var/run/domain.de.sock;
    fastcgi_index            index.php;
include                  conf/fastcgi.conf;
}
}

希望它也对其他人有所帮助。 感谢您的支持。

【讨论】:

猜你喜欢
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 2013-07-22
  • 2015-01-14
  • 2021-11-26
  • 2015-03-03
  • 2017-03-09
  • 1970-01-01
相关资源
最近更新 更多