【问题标题】:Per project documentroot每个项目的文档根目录
【发布时间】:2023-03-10 08:39:01
【问题描述】:

我已经有一个本地服务器几个月了,每次我开始一个新项目时,我都需要使用服务器的根目录而不是项目的根目录。

在我的服务器上我有:

htdocs
-- project1
---- images
---- js
---- css
-- project2
// etc. //

当我去 rawox.co.cc(这是我家的开发服务器)时,它会重定向到投资组合文件夹(rawox.co.cc/portfolio/)另一个项目是 menology(rawox.co.cc/月经/)。在这些项目的 css 中,我必须使用 background-image: url(../images/logo.png;。当我将项目上传到公共服务器时,css 会因为 ../ 而停止工作。

我个人的想法是,这是因为http://rawox.co.cc/ 在我的 apache 设置中被设置为 DocumentRoot。我将如何解决这个问题?

【问题讨论】:

    标签: apache xampp


    【解决方案1】:

    您可以在 httpd.conf 中使用虚拟主机。

    <VirtualHost 10.1.2.3:80>
        ServerAdmin webmaster@host.example.com
        DocumentRoot /www/docs/host.example.com
        ServerName host.example.com
        ErrorLog logs/host.example.com-error_log
        TransferLog logs/host.example.com-access_log
    </VirtualHost> 
    

    为每个项目创建一个单独的 project1-vhost.conf 文件并将其包含在其中

    include project1-vhost.conf
    

    在您的 httpd.conf 文件中。这样您就可以轻松激活和停用每个项目

    http://httpd.apache.org/docs/2.0/vhosts/examples.html http://httpd.apache.org/docs/2.2/en/mod/core.html#virtualhost

    //编辑

    Alias /project1 /path/to/project
    <Location /path/to/project>
        Order Allow, Deny
        Allow from All
        ...
    </Location>
    

    【讨论】:

    • 我知道这一点,但我不想使用 Servername host.example.com,我想要 Servername example.com/host。
    • 那你可以试试 Alias /project1 /path/to/project1 Order Allow, Deny ...
    猜你喜欢
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 1970-01-01
    • 2015-10-07
    • 2015-04-02
    相关资源
    最近更新 更多