PRESTASHOP 1.7.8.6 MULTISTORE NGINX重写规则
我在
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 未显示图像
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要解释这里发生的情况,我需要参考nginx 请求处理阶段 ,一个主题实际上没有多少人理解。
这是在
ngx_http_server_rewrite_phase
上执行的一组重写规则:如您所见,它们都不匹配
/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
级别之前重写图像请求的规则集:请注意,我不使用
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
:As you can see, none of them matches the
/shop-1/45-medium_default/skirt.jpg
request URI. So on the next turn, during theNGX_HTTP_FIND_CONFIG_PHASE
yourlocation /shop-1/ { ... }
will be selected to handle the request. Next, afterrewrite ^/shop-1/(.*)$ /$1 last;
rule being executed, your request URI will be rewritten to/45-medium_default/skirt.jpg
, and due to the usedlast
flag on therewrite
directive theNGX_HTTP_FIND_CONFIG_PHASE
will be executed again. However theNGX_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 theserver
level before the ruleset for rewriting image requests:Note that I don't use
last
(orbreak
) 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.