PRESTASHOP 1.7.8.6 MULTISTORE NGINX重写规则

发布于 2025-02-03 04:04:44 字数 1066 浏览 3 评论 0原文

我在

location /shop-1/ {
  rewrite ^/shop-1/(.*)$ /$1 last;
  try_files $uri $uri/ /index.php?$args;
}
location /shop-2/ {
  rewrite ^/shop-2/(.*)$ /$1 last;
  try_files $uri $uri/ /index.php?$args;
}

遵循 https://devdocs.prestashop.com/1.7/basics/installation/nginx/

现在Q是父域正确导航并显示映像,但校正为 http://example.com/ {shop-1-1 },但未在多派urls上显示图像,获取nginx 404错误在Multishop URL上,但在父域上显示相同的图像。

示例:

http://example.com/shop.com/shop-1/45-medium_default/ skirt.jpg 未显示图像

http://example.com/45-medium_default /skirt.jpg 显示图像

I install the prestashop 1.7 as a multistore and write nginx rewrite rule as

location /shop-1/ {
  rewrite ^/shop-1/(.*)$ /$1 last;
  try_files $uri $uri/ /index.php?$args;
}
location /shop-2/ {
  rewrite ^/shop-2/(.*)$ /$1 last;
  try_files $uri $uri/ /index.php?$args;
}

I follow the nginx conf file from https://devdocs.prestashop.com/1.7/basics/installation/nginx/

Now the Q is Parent domain navigating correctly and showing images but multistore redirected corrected to http://example.com/{shop-1 or shop-2} but not showing the images on the multishop urls, getting nginx 404 error on multishop url but same image showing on a parent domain.

example:

http://example.com/shop-1/45-medium_default/skirt.jpg not showing the image

http://example.com/45-medium_default/skirt.jpg showing the image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷荒 2025-02-10 04:04:44

要解释这里发生的情况,我需要参考nginx 请求处理阶段 ,一个主题实际上没有多少人理解。

这是在ngx_http_server_rewrite_phase上执行的一组重写规则:

rewrite ^/(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([\w.-]+)/.+\.jpg$ /img/c/$1.jpg last;

如您所见,它们都不匹配/shop-1/45-medium_default/skirt.jpg Uri。因此,在下一个回合中,将选择ngx_http_find_config_phase您的location/shop-1/{...}将选择处理请求。接下来,在重写 ^/shop-1/(.fore> pument; $ 1 last;执行规则后,您的请求URI将被重写为/45-Medium_default/skirt.jpg ,并且由于重写指示ngx_http_find_find_config_phase将再次执行。但是,ngx_http_server_rewrite_phase将不会再次执行,并且不会根据这些规则重写新的URI。相反,您应该做的是将重写规则放在server级别之前重写图像请求的规则集:

rewrite ^/(?:shop-1|shop-2)(/.*) $1;
... image URIs rewrite rules here

请注意,我不使用last代码>(或break)该规则的标志,因为将触发此重写后,不应终止重写规则链。您在问题中显示的这两个位置都不需要。

To explain what happened here I need to refer to nginx request processing phases, a subject not many people actually understand correctly.

Here is a set of rewrite rules being executed at the NGX_HTTP_SERVER_REWRITE_PHASE:

rewrite ^/(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
rewrite ^/(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(-[\w-]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/c/([\w.-]+)/.+\.jpg$ /img/c/$1.jpg last;

As you can see, none of them matches the /shop-1/45-medium_default/skirt.jpg request URI. So on the next turn, during the NGX_HTTP_FIND_CONFIG_PHASE your location /shop-1/ { ... } will be selected to handle the request. Next, after rewrite ^/shop-1/(.*)$ /$1 last; rule being executed, your request URI will be rewritten to /45-medium_default/skirt.jpg, and due to the used last flag on the rewrite directive the NGX_HTTP_FIND_CONFIG_PHASE will be executed again. However the NGX_HTTP_SERVER_REWRITE_PHASE won't be executed again, and a new URI won't be rewritten according to those rules. What you should do instead is to place a rewrite rule at the server level before the ruleset for rewriting image requests:

rewrite ^/(?:shop-1|shop-2)(/.*) $1;
... image URIs rewrite rules here

Note that I don't use last (or break) flag for this rule since the rewrite rules chain should not be terminated after this rewrite will be triggered. None of those two locations that you show in your question will be needed at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文