magento2 为什么有两个可能的根目录(Why Magento 2 have 2 possible root folder?)

来源:互联网 发布:vb多肽公司 编辑:程序博客网 时间:2024/06/06 08:28

Magento 2 have 2 possible root folder:

magent2 有两个可能的根目录



/path/to/magento2/index.php   
/path/to/magento2/pub/index.php
One is at the absolute top level of Magento 2’s distribution folder. The second is inside the “pub” folder.
一个在magneto2项目的根目录下,另一个在pub文件夹下

If I set base URL is either of them, magento is working perfectly.

如果我使用两个中的任意一个设置为base URL,magento都可以很完美的工作/运行。



Can anyone explain me why Magento 2 using 2 root folder like that ?

那有谁可以帮我解释一下:为什么magento 有两个根目录文件夹呢?

--------------------------------------------

 Using /pub is better, because it is more secure. Why? Because in that case most of Magento's code will live outside the public document root, so the possible attack surface is smaller. In other words, when you use the top level folder as document root, you have to make sure that various folders (such as app) are explicitly denied in your webserver configuration.

That said, not everybody can configure the document root, so Magento provided a top level index.php for compatibility. 

使用/pub文件夹下的index.php 更好。因为他更加安全。为什么?因为这种情况下,大部分的magento代码都将在公共的根目录以外运行,所以也减少了受到攻击的可能性。
换而言之,当你使用最高层的文件夹作为文件根目录的话,你必须确定各种文件夹(比如app文件夹)确实是在你的web服务器的配置里被拒绝访问了的。

也就是说,并不是每一个人都会(正确)配置项目的文件根目录,所以为了通用性,magento提供了一个顶层的index.php。


翻译的不好请多谅解。

0 0