[英]Set up apache2 for an application
I created an small web application using web.py. 我使用web.py创建了一个小型Web应用程序。 When deploying and accessing the application through the web browser I get an error related to the location of javascript files. 通过Web浏览器部署和访问应用程序时,出现与javascript文件位置有关的错误。
I followed the structure recommended in learnpythonthehardway.org, so I have the following: 我遵循了learnpythonthehardway.org中推荐的结构,因此具有以下内容:
myapp/
bin/
app.py
python_module/
my_module.py
static/
javascript/
myScript.js
templates/
index.html
Within index.html I have next line: 在index.html中,我有下一行:
<script type="text/javascript" src="/static/javascript/myScript.js"></script>
I've uploaded the files to /var/www/html/myapp 我已将文件上传到/ var / www / html / myapp
In apache I have to following configuration: 在apache中,我必须进行以下配置:
WSGIScriptAlias /myapp /var/www/html/myapp/bin/app.py
DocumentRoot /var/www/html
Now, when I access http://example.com/myapp I got a 404 error because the application is looking for the javascript in http://example.com/static/javascript/myScript.js 现在,当我访问http://example.com/myapp时 ,出现了404错误,因为该应用程序正在http://example.com/static/javascript/myScript.js中寻找javascript
What is the configuration to look for the javascript files in the right location, other than change the src attribute in the script tag within index.html? 除了更改index.html中script标记中的src属性以外,在正确位置查找javascript文件的配置是什么?
Thanks. 谢谢。
Change: 更改:
<script type="text/javascript" src="/static/javascript/myScript.js"></script>
to: 至:
<script type="text/javascript" src="/myapp/static/javascript/myScript.js"></script>
It just is looking for an absolute url based on the root of the webserver. 它只是在基于Web服务器的根目录查找绝对URL。 /static
means in /var/www/html/static
. /static
在/var/www/html/static
。 You can also get rid of the first /
if you want but you would have to be careful if you have any subdirectory handling otherwise it will try to find static
inside that other directory. 如果需要,您也可以删除第一个/
,但是如果要处理任何子目录,则必须小心,否则它将尝试在该其他目录中查找static
文件。
The solution for this is to add the following line to apache configuration: 解决方案是将以下行添加到apache配置中:
Alias /static /var/www/html/movies/static
As the apache documentation says: 如apache文档所述:
"The Alias and ScriptAlias directives are used to map between URLs and filesystem paths" “ Alias和ScriptAlias指令用于在URL和文件系统路径之间进行映射”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.