最好的方法是什么?子域和 MySQL
我正在询问您对我的下一个项目的意见。
我计划制作一个提供服务的网站,所有用户都将拥有自己的子域(user.mydomain.com)和自己的网站。
首先,我想真正制作真正的子域,自动生成网站代码到他们的文件夹中,创建自己的数据库等。
问题#1:当我需要主页(mydomain.com)中所有子域数据库的一些信息时,我该如何做去拿那些?
这是更好的方法吗?只使用一个数据库和所有用户正在使用的动态代码,然后重新编写地址,就像它是子域一样(mydomain.com?user = myuser - > myuser.mydomain.com)
如果有人有使用过的经验像我计划的那样,如果有提示和技巧可以正确完成,那就太好了! :)
谢谢!
I'm asking your opinions about my next project..
I'm planning to make website which offers services where all users would be have own subdomain (user.mydomain.com) and own website.
First I was thinking to really make real subdomain, generating automatically website code into their folder, creating own database etc..
Question #1: When I need some information from all subdomains databases in my main page (mydomain.com), how can I fetch those?
Would it be better way just use one database and dynamic code what all users are using but then re-write address like it would be subdomain (mydomain.com?user=myuser -> myuser.mydomain.com)
If someone have experience with something like what I was planning, would be nice to have tips and tricks do it right! :)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您为所有用户拥有一个通用代码库,只需读取域名并使用该信息,因此需要维护的代码会少很多。
想象一下,您发现为某个子域生成的代码中有错误。
您要么需要纠正 1 个地方,要么需要纠正 1 个地方 + 用户数量。
It will be alot of less code to maintain in you have one common codebase for all users, that just reads the domain name and uses that information.
Imagine that you discover an error in the code that was generated for one of the subdomains.
Either you would have one place to correct, or you would have 1 place + the number of users to correct.
您可能希望所有子域都指向相同的代码库,并将子域视为拉出的参数并标识它是该应用程序的哪个实例。您的数据库中需要一个表来存储有关每个实例的信息,然后用户帐户、用户数据等将全部绑定到特定实例。
You'll probably want all of the subdomains to point to the same codebase and treat the subdomain as an argument that is pulled out and identifies which instance of this application it is. You'll need a table in your db that will store information about each instance and then user accounts, user data, etc will all be tied back to a specific instance.