具有通用文件的多个站点

发布于 2024-08-11 23:01:19 字数 678 浏览 4 评论 0原文

我已经开发了 50 多个网站,除了 CSS 和 IMAGES 之外,它们都使用完全相同的文件,目前我每次创建新网站并上传不同的 css 和图像时都会复制这些文件。

将其简单地放入所有常见文件的 1 个主位置的最佳实践是什么?

这是我当前每个站点的结构:

/home/ftpuser/public_html/commonfile1.php
/home/ftpuser/public_html/commonfile2.php
.....
/home/ftpuser/public_html/commonfileN.php
/home/ftpuser/public_html/commonfolder1/
/home/ftpuser/public_html/commonfolder2/
.....
/home/ftpuser/public_html/commonfolderN/
/home/ftpuser/public_html/css/
/home/ftpuser/public_html/css/mycssfiles.css
/home/ftpuser/public_html/images/
/home/ftpuser/public_html/images/myimages.jpg

我如何将每个站点的所有公共文件都放在 1 个位置,同时仍然能够拥有定制的 css 和图像。

我正在使用 Apache、PHP、Centos

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images.

What would be the best practice to simply this into 1 main location for all common files?

Here is my current structure for each site:

/home/ftpuser/public_html/commonfile1.php
/home/ftpuser/public_html/commonfile2.php
.....
/home/ftpuser/public_html/commonfileN.php
/home/ftpuser/public_html/commonfolder1/
/home/ftpuser/public_html/commonfolder2/
.....
/home/ftpuser/public_html/commonfolderN/
/home/ftpuser/public_html/css/
/home/ftpuser/public_html/css/mycssfiles.css
/home/ftpuser/public_html/images/
/home/ftpuser/public_html/images/myimages.jpg

How would I go about making all the common files located in 1 place for each site while still being able to have bespoke css and images.

I am using Apache, PHP, Centos

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

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

发布评论

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

评论(5

夏末染殇 2024-08-18 23:01:19

我会让您的 50 个虚拟主机都使用相同的 DocumentRoot。这样您就可以保证所有站点都将使用相同的通用文件。

要选择不同的 css 和图像目录,请使用 Alias 指令指向每个 VirtualHost 的显式目录。

I would have your 50 virtual hosts all using the same DocumentRoot. That way you guarantee that all sites will be using the same common files.

To pick up different css and image directories, use the Alias directive to point to explict directories for each VirtualHost.

无法回应 2024-08-18 23:01:19

最明显的解决方案,假设所有不同的站点都托管在同一服务器/文件系统上,类似于:

+- common files (outside web root)
|
+- httpdocs (web root)
   |
   +--+- website 1 specific files
   |      |
   |      +- images (etc)
   |
   +--+- website 2 specific files
          |
          +- images (etc)

根据上图,您需要做的就是包含共享位置中的相关文件,并覆盖/否决出于站点特定性的目的,使用站点特定文件(无论存储在 Web 根目录内部还是外部)。

如果您的站点都托管在不同的服务器上,那么情况会变得更加复杂,因为任何常见文件都必须托管在 Web 根目录中的某个位置(可通过 http 访问)。这并不理想,尽管没有什么可以阻止它工作,但就带宽使用和跨站点安全问题而言,它可能会出现问题。

使用虚拟主机,您就处于两种选择之间的中间位置;只要它们都可以访问相同的文档根目录,您仍然可以使用包含内容(如 由 dland 在这些答案的其他地方建议)。

The most obvious solution, assuming that all the different sites are hosted on the same server/filesystem, would be something akin to:

+- common files (outside web root)
|
+- httpdocs (web root)
   |
   +--+- website 1 specific files
   |      |
   |      +- images (etc)
   |
   +--+- website 2 specific files
          |
          +- images (etc)

With the above diagram, all you need to do is include the relevant files from the shared location, and override/overrule for the purposes of site specificity using the site-specific files (whether stored inside, or outside, of the web-root).

If your sites are all hosted across different servers then it gets a little more complicated, since any common files would have to be hosted somewhere in the web-root (accessible via http). This isn't ideal, though there's nothing stopping it working, but in terms of bandwidth usage and issues with cross-site security, it's likely to be problematic.

With Virtual Hosts, you're at something of a halfway house between the two options; so long as they can all access the same document root you're still able to use the includes (as suggested by dland elsewhere in these answers).

扭转时空 2024-08-18 23:01:19

如果这些站点都在同一台服务器上,您只需将这些文件包含在 php include 中即可。

那么你可以将它们包含在内,就好像它们与当前的 php 文件位于同一目录中一样。

If these sites are all on the same server, you can just include the files in your php includes.

then you can just include them as if they were in the same directory as your current php file.

时常饿 2024-08-18 23:01:19

我认为你可以从主文件夹中 #include 所需的文件,你必须使其可以从所有站点访问(使用软链接将导致服务器认为它们位于每个站点的目录中)

使用软链接将使从路径问题来看,它更容易,并且您不需要使用 httpdocs 目录“外部”的路径。

I think you can just #include the files that you need from the main folder, you will have to make it accessible from all the sites (using soft links will cause the server to think they are in each site's directory)

Using soft links will make it easier from the paths concerns, and you won't need to use paths "outside" your httpdocs directory.

雄赳赳气昂昂 2024-08-18 23:01:19

如果它们位于同一服务器上,您可以仅对文件进行符号链接:

ln -s /home/ftpuser/public_html/commonfile1.php /home/ftpuser/public_html/commonfile2.php

这在涉及不同用户(文件所有者)的共享托管设置中会崩溃。

If they're on the same server, you could just symbolic link the files:

ln -s /home/ftpuser/public_html/commonfile1.php /home/ftpuser/public_html/commonfile2.php

This breaks down in a shared hosting setup where different users (file owners) are involved.

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