同一虚拟主机上的两个Django应用程序存在间歇性问题

2024-10-04 03:26:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个Django应用程序(appsystem和testapp)运行在不同的文件夹中,这些文件夹在相同的apache虚拟主机设置中启用(请参阅最后的conf文件)。在

一个应用程序在域的根目录上显示一个页面,这个页面似乎总是运行良好,但是当我转到一个应该指向第二个应用程序的URL时,它第一次失败了,抱怨它找不到数据库表,尽管我可以在debug页面中看到加载正确的设置。在

如果我刷新页面,那么它(testapp)会正常工作,直到我从appssytem返回一个页面。如果我这样做并返回testapp,我必须刷新页面。在

这两个应用程序都在使用sqlite进行身份验证,但是从appsystem的设置文件中删除身份验证和sqlite引用似乎没有什么不同。在

我这样做的原因是因为这样做的想法是,显示根页面的应用程序(以及一些具有唯一url的管理页面)将列出已安装的其他django应用程序,并显示要单击的链接。在

我还怀疑它可能与会话相关,因为我可以在另一个浏览器中直接转到testapp,即使在第一个实例中也可以正常工作。因此,我给了每个django应用程序自己的SESSION_COOKIE_NAME值,但这似乎没有帮助。在

有人知道问题出在哪里吗?在

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /app_www_root

    RewriteEngine On
        # the root of the box should show the system index - a list of installed apps
        RewriteRule ^/$ /appsystem/system_index/ [PT]

    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /app_www_root/>
        Order allow,deny
        allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

    Include /etc/apache2/installed-apps/

    ## this is what gets pulled in by the include ##
    Alias                 /testapp/static       /testapp/static
    Alias                 /testapp/logs         /var/log/testapp
    WSGIScriptAliasMatch  ^/testapp             /testapp/django.wsgi

    <Directory "/testapp">
        Order allow,deny
        Allow from all
    </Directory>

    <Directory "/var/log/testapp">
        Order allow,deny
        Allow from all
    </Directory>

    <Location "/testapp/logs">
        SetHandler none
        Options +Indexes
    </Location>

    <Location "/testappl/static">
        SetHandler none
        Options -Indexes
        Options +Includes
        AddOutputFilter INCLUDES .html
    </Location>
    ## end of included file ##

  # wsgi docs advise against trailing slash below
  WSGIScriptAlias /appsystem  /app_sys/django.wsgi

</VirtualHost>

Tags: ofthedjangologapp应用程序varlocation
3条回答

你读过http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango吗?在

我怀疑如果您在守护程序模式下使用mod unwsgi(即通过WSGIDaemonProcess),您的问题会得到解决。在

尝试用modwsgi在virtualenv中运行它们。在

FWIW,你的配置有很多问题。在

  1. 为什么要使用WSGIScriptAliasMatch指令?您应该将其替换为WSGIScriptAlias。不要正确地使用WSGIScriptAliasMatch,它会增加反向URL解析。

  2. 不需要使用“SetHandler none”。这是您可能需要为mod\upython做的事情,而不是mod\wsgi。

  3. 使用Location-directive块将指令应用于静态文件资源是不好的做法。您应该使用Directory指令将它们应用到特定的目录。

正如其他人指出的,最好使用守护程序模式。如果这样做有效,但是您将两个应用程序委托给同一个单一守护程序模式进程,那么您可能会遇到多进程问题,也就是说,您的应用程序无法处理同时在多个进程中运行。如果您将每个进程委派给它自己的守护进程组,那么即使在不同的子解释器中运行它们,在同一个进程中也可能存在问题。在

相关问题 更多 >