【问题标题】:404 error for some internal sub-store pages in magento with nginx使用 nginx 在 magento 中的某些内部子存储页面出现 404 错误
【发布时间】:2020-06-14 05:19:14
【问题描述】:

我无法访问我商店的一些内部页面,但是禁用 web/seo/use_rewrites 效果很好。

我认为是一些nginx配置不对,我尝试创建一个rewriter,但是位置很多。

这是我的会议:

upstream fastcgi_backend {
    server unix:/run/php-fpm/www.sock;
}

server {

    listen 80 reuseport default_server;

    server_name  _;

    root /var/www;

    index index.html index.php;

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

    location ~ .php/ {
          rewrite ^(.*.php)/ $1 last;
    }

    location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php {
        fastcgi_pass    fastcgi_backend;
        fastcgi_index  index.php;

        fastcgi_buffers 1024 4k;

        fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
        fastcgi_param  PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
        fastcgi_read_timeout 600s;
        fastcgi_connect_timeout 600s;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;        
    }

    error_log /var/log/nginx/debug.log debug;  
    access_log /var/log/nginx/debug.log;
}

如果我设法在每个文件夹子存储后添加一个 index.php 的重写器,我认为问题将得到解决。

我尝试创建一个始终添加 index.php 的规则,但是它会下载而不是执行。

location / {
    try_files $uri $uri/ /index.php$is_args$args @fallback;
}

location @fallback {
    rewrite ^/(\w*)/(.*)$ /$1/index.php/$2 last;
}

【问题讨论】:

  • 请检查rewrite module enable in local or not?
  • 是的,它被激活了,以至于我创建的规则(甚至是错误的规则)改变了应用程序的行为。
  • 你能给我看一下.htaccess文件吗?
  • 我正在使用 nginx/1.17.8 。

标签: nginx magento url-rewriting magento2 nginx-location


【解决方案1】:

好的,nginx 按照写入的顺序读取位置,所以我需要为子存储创建一个规则,我必须重新排序,这样就不会出现无限循环的规则。

这就是我所做的:

location ~ (index|get|static|errors/report|errors/404|errors/503|health_check)\.php {
    fastcgi_pass    fastcgi_backend;
    fastcgi_index  index.php;

    fastcgi_buffers 1024 4k;

    fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=off";
    fastcgi_param  PHP_VALUE "memory_limit=768M \n max_execution_time=18000";
    fastcgi_read_timeout 600s;
    fastcgi_connect_timeout 600s;

    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;        
}

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

location ~ ^/([a-z]+)/(.*)$ {
  try_files  $uri   $uri/ /$1/index.php/$2?$query_string;
}

location ~ .php/ {
      rewrite ^(.*.php)/ $1 last;
}

【讨论】:

    猜你喜欢
    • 2013-08-04
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 1970-01-01
    • 2022-12-14
    • 2019-10-06
    • 1970-01-01
    • 2015-05-31
    相关资源
    最近更新 更多