托管 Apache 的 Django 静态文件 [英] Django Static File Hosting an Apache

查看:20
本文介绍了托管 Apache 的 Django 静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我一直在开发的 Django 站点从开发服务器阶段移到真正的托管环境中.目前,我只是在我的个人机器上托管.我已经安装了 Apache 和 mod-wsgi,但是我在获取静态文件时遇到了问题.我很确定它与Apache有关.这是我的站点配置文件:

I'm trying to move a Django site I have been working on out of the dev server stage and into a real hosting environment. For the time being, I'm just hosting on my personal machine. I already have Apache and mod-wsgi installed, but I'm having issues getting static files up. I'm pretty sure it has to do with Apache. Here is my config file for the site:

<VirtualHost *:80>

    ServerName localhost
    ServerAlias daifotis.dyndns.org
    ServerAdmin webmaster@daifotis.com

    DocumentRoot /home/daifotis/code/

    Alias /media/ /home/daifotis/code/feris/sitestatic
    Alias /static/ /home/daifotis/code/feris/sitestatic
    #AliasMatch ^/([^/]*\.css) /home/daifotis/code/feris/sitestatic/$1

    <Directory /home/daifotis/code/feris/sitestatic>
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/daifotis/code/feris>
        Order allow,deny
        Allow from all
    </Directory>

    <Directory /home/daifotis/code/feris/jobsite>
        Order allow,deny
        Allow from all
    </Directory>

    WSGIDaemonProcess feris processes=2 threads=15 display-name=%{GROUP}
    WSGIProcessGroup feris

    WSGIScriptAlias / /home/daifotis/code/feris/apache/django.wsgi

    <Directory /home/daifotis/code/feris/apache>
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

我正在尝试从我使用静态别名的目录托管文件.当我尝试加载网站时,所有内容都出现了,但没有 css.此外,当我点击我的网址 www.server.com/static/时,页面会显示目录的正确内容.但我不明白的是,为什么如果我单击链接查看文件,它会说该 URL 不存在.我已经坚持了一段时间,所以任何帮助将不胜感激.

I'm trying to host the files from the directory I alias with static. When I try to load the site, all the content comes up but no css. Also, when I hit my url www.server.com/static/, the page displays with the proper content of the directory. What I don't understand though, is why if I click on a link to view a file, it says that URL does not exist. I've been stuck on this for awhile so any help would be much appreciated.

推荐答案

想通了.我在这一行有一个 apache 配置错误:

Figured it out. I had an apache config error on this line:

Alias /static/ /home/daifotis/code/feris/sitestatic

我应该在没有尾部斜杠的情况下编写静态.使用尾部斜杠 Apache 不会扩展 URL 路径.

I should have written static without the trailing slash. With the trailing slash Apache will not expand the URL path.

Alias /static /home/daifotis/code/feris/sitestatic

这篇关于托管 Apache 的 Django 静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆