如何为多个子域设置 Yii,以便受保护的文件夹位于每个子域的文档根目录之外
我决定开始使用 OOP 和 PHP 框架进行编码。我已经在开发服务器上成功安装了 Yii 并创建了一个 web 应用程序。现在,出于安全原因,我想将受保护的文件夹移动到文档根目录之外的级别。我的问题是当我也将使用 Yii 的多个子域时如何做到这一点。
我有 PHP 经验,但不是 OOP 风格,这是我进入 OOP 和框架的第一步。另外,我在Ubuntu上安装了LAMP系统用于开发。
我的路径结构如下,与生产服务器匹配。我有一个顶级网站和多个其他顶级网站以及其中一个顶级网站的子域网站。
顶级网站 - /home/mark/public_html/{网站一个文件}
顶级网站 - /home/mark/public_html/website-two.com/{website-two files}
顶级网站 - /home/mark/public_html/website- Three.com/{website- Three files}
我的子域 - /home/mark/public_html/sub1.website- Three.com/{sub files}
我的子域 - /home/mark/public_html/sub2.website- Three.com/{sub2 files}
我的子域 - /home/mark/public_html/sub3.website- Three.com/{sub3 files}
我已将 Yii 安装在:/home/mark/Yii
我已在以下位置创建了一个 Web 应用程序:/home/mark/public_html/sub1 .website-third.com 并在本地访问 Yii web 应用程序 http://sub1.website-third/ 。 ...我不要使用 http://localhost 因为我有虚拟主机和子域。所有这些都有效,并将在网站三下的其他子域中创建更多网络应用程序。
我可以将受保护的文件夹重命名为 sub_protected 并将其放置在 /home/mark 中,然后对于我的下一个 webapp,将受保护的文件夹命名为 sub2_protected 等等?我应该使用不同的路径结构吗???另外,我相信我需要编辑每个站点的 protected/config/main.php 以反映更改???
任何帮助将不胜感激。迫不及待地想进行此配置,以便我可以进一步深入了解 Yii ...到目前为止看起来非常有趣。
I have decided to start coding using OOP and a PHP framework. I have successfully installed Yii on a development server and created a webapp. Now, I would like to move the protected folder to a level outside the document root for security reasons. My question is how to do this when there are multiple subdomains that I will also be using Yii with.
I have experience with PHP, but not in an OOP style and this is my initial step into OOP and frameworks. Also, I have a LAMP system installed on Ubuntu for development.
My path structure is below, which matches the production server. I have a top level site and multiple other top level sites and subdomain sites for one of the top level sites.
top level site - /home/mark/public_html/{website one files}
top level site - /home/mark/public_html/website-two.com/{website-two files}
top level site - /home/mark/public_html/website-three.com/{website-three files}
my sub domains - /home/mark/public_html/sub1.website-three.com/{sub files}
my sub domains - /home/mark/public_html/sub2.website-three.com/{sub2 files}
my sub domains - /home/mark/public_html/sub3.website-three.com/{sub3 files}
I have Yii installed at: /home/mark/Yii
I have created a webapp at: /home/mark/public_html/sub1.website-three.com and access the Yii webapp locally at http://sub1.website-three/ ....I don't use http://localhost since I have virtual hosts and sub domains. All of this works, and will be creating more webapps at other subdomains under website-three.
Can I rename the protected folder to sub_protected and place it at /home/mark, and then for my next webapp, name the protected folder sub2_protected and so on? Should I use a different path structure??? Also, I believe I will need to edit the protected/config/main.php for each site to reflect the changes???
Any assistance would be greatly appreciated. Can't wait to get this configured so I can dive further into Yii ...looks very intriguing so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将受保护的文件夹命名为任何您想要的名称,并将其放置在您的网络服务器用户有权访问的文件系统上的任何位置,因此 /home/mark/sub*n*_protected 方案可以工作。
但是,特别是如果您的站点相似并且具有任何共享代码,那么使用一个受保护的文件夹并在主配置文件中设置一组 urlManager 规则并根据主机名加载适当的规则可能会更有效。然后,您可以为每个主机以及视图目录提供专用控制器。我经常对移动版本执行此操作,您还可以在其中添加移动检测。
如果站点不同,使用单独的受保护目录也可能有意义。例如,我将使用一个单独的受保护目录来存放基于 Gii 生成的脚手架的管理工具。
如果这些网站非常相似,您可能还想查看主题:
http://www.yiiframework.com/doc/guide/1.1/en /topics.theming
You can name the protected folder whatever you want and put it anywhere on your file system that your webserver user has access to, so, yes /home/mark/sub*n*_protected scheme would work.
However, particularly if your sites are similar and have any shared code, it might be more efficient to use one protected folder and set up an array of urlManager rules in your main config file and load the appropriate rules base on the host name. You can then have dedicated controllers for each host as well as views directories. I've often done this for mobile versions where you can also add mobile detection to the mix.
If the sites are distinct, using separate protected directories might sense as well. E.g., I'll use a separate protected directory for admin tools based on the Gii-generated scaffolding.
If the sites are very similar, you also might want to check out Themes:
http://www.yiiframework.com/doc/guide/1.1/en/topics.theming
当然,您可以将受保护的文件夹放置在文档根目录下。
只需在您的配置中使用下一个代码用于网站:
您的
protected
文件夹就会被查看Sure you can place protected folder under the document root.
Just use for website one next code in your config:
and your
protected
folder will be looked at