在虚拟机上设置django

时间:2012-07-04 01:39:59

标签: python django apache

我有一台运行peppermint os 2的虚拟机(基本上是ubuntu)。

我一直在尝试按照以下教程:http://jeffbaier.com/articles/installing-django-on-an-ubuntu-linux-server/

到目前为止,一切都已经按照教程的说明进行了解决。我的Apache httpd.conf文件如下所示:

ServerName localhost

MaxRequestsPerChild 1

    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE myproject.settings
    PythonPath "['/home/<my_user_name>/django_projects'] + sys.path"

    SetHandler None

    SetHandler None

    SetHandler None

    SetHandler None

每当我尝试并进入“localhost /”时,它会向我显示/ var / www /文件夹(index.html文件中显示“It works!”)而不是应该出现的django首页。我的/ var / www的内容是“admin_media”和“media”

我需要做什么? 谢谢。

1 个答案:

答案 0 :(得分:1)

尝试mod_wsgiuwsgi,它更容易配置,强大且更快。

你也可以在django doc - use django with mod_wsgi

获得帮助

当你使用ubuntu时,mod_wsgi的安装很简单:

sudo apt-get install libapache2-mod-wsgi

如果没有启用mod-wsgi,请执行以下操作:

cd /etc/apache2/mod_available
cp mod_wsgi.* ../mod_enable
sudo service apache2 restart

使用mod_python,apache配置为:

ameVirtualHost *:80
NameVirtualHost *:8000
Listen 80
Listen 8000

WSGIDaemonProcess xxxx display-name=%{GROUP}
WSGIProcessGroup xxxx
<VirtualHost *:80>
    ServerName  xxxx
    WSGIScriptAlias / /home/xxx/xxxx/xxxx.wsgi

    Alias /js "/home/xxx/xxxx/xxxx/public/js"
    <Location "/js">
        SetHandler None
    </Location>
    <Directory "/home/xxx/xxxx/xxxx/public/js">
       Order Deny,Allow
       Allow from all
    </Directory>
</VirtualHost>

NameVirtualHost *:8080
<VirtualHost *:8080>
        WSGIScriptAlias / /home/xxxx/xxxx/wsgi_handler.py
        #WSGIDaemonProcess xxxx_com22 user=xxxx processes=1 threads=10
        #WSGIProcessGroup xxxx_com1

        Alias /upload/ "/home/xxxx/xxxx/upload/"
        <Directory /home/xxxx/xxxx/upload/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
Listen 8080

并且对于使用uwsgi,我建议使用nginx + uwsgi,如果你感兴趣,我会发布教程和配置。