【问题标题】:Set up apache2 for an application为应用程序设置 apache2
【发布时间】:2015-10-19 17:35:51
【问题描述】:

我使用 web.py 创建了一个小型 Web 应用程序。通过网络浏览器部署和访问应用程序时,我收到与 javascript 文件位置相关的错误。

我遵循了 learnpythonthehardway.org 中推荐的结构,所以我有以下内容:

   myapp/
        bin/
            app.py
        python_module/
            my_module.py
        static/
            javascript/
                myScript.js
        templates/
            index.html

在 index.html 中我有下一行:

<script type="text/javascript" src="/static/javascript/myScript.js"></script>

我已将文件上传到 /var/www/html/myapp

在 apache 中我必须进行以下配置:

WSGIScriptAlias /myapp /var/www/html/myapp/bin/app.py

DocumentRoot /var/www/html

现在,当我访问 http://example.com/myapp 时出现 404 错误,因为应用程序正在 http://example.com/static/javascript/myScript.js 中寻找 javascript

除了更改 index.html 内 script 标签中的 src 属性外,在正确位置查找 javascript 文件的配置是什么?

谢谢。

【问题讨论】:

    标签: javascript apache web.py


    【解决方案1】:

    变化:

    <script type="text/javascript" src="/static/javascript/myScript.js"></script>
    

    到:

    <script type="text/javascript" src="/myapp/static/javascript/myScript.js"></script>
    

    它只是在寻找基于网络服务器根目录的绝对 url。 /static 表示/var/www/html/static。如果你愿意,你也可以去掉第一个/,但如果你有任何子目录处理,你必须小心,否则它会尝试在另一个目录中找到static

    【讨论】:

    • 感谢您的回答,我找到了另一个解决方案。
    【解决方案2】:

    解决方案是在 apache 配置中添加以下行:

    Alias /static /var/www/html/movies/static
    

    正如 apache 文档所说:

    “Alias 和 ScriptAlias 指令用于映射 URL 和文件系统路径”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-09
      • 2012-05-01
      • 1970-01-01
      • 2013-02-12
      • 2014-10-07
      • 1970-01-01
      • 1970-01-01
      • 2011-10-29
      相关资源
      最近更新 更多