无法解析在WSGI / Apache上运行的Flask应用程序中的路径

时间:2017-04-22 03:00:00

标签: flask mod-wsgi wsgi

我正在尝试使用wsgi在Ubuntu VPS中部署FLASK应用程序,但是我收到内部服务器错误。检查apache.log会出现以下错误:

  

没有这样的文件或目录:' files / filesystem / filesystem.pickle'。

我的目录树在/var/www/下显示如下:

dmft_seacrh_engine
    files
        filesystem
            filesystem.pickle
    dmft_search.wsgi
    dmft_search
        controllers
            search.py

我正在尝试打开filesystem.pickle内的search.py,如下所示:

with open('/files/filesystem/filesystem.pickle', 'rb') as handle:
    filesystem = pickle.load(handle)

dmft.wsgi文件的内容为:

activate_this = '/opt/dmft/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/dmft_search_engine")

from dmft_search import app as application

这就是我的conf文件的外观:

<VirtualHost *:80>
                ServerName      dmft_search_engine.com
                WSGIScriptAlias / /var/www/dmft_search_engine/dmft_search.wsgi
                <Directory /var/www/dmft_search_engine/dmft_search/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/dmft_search_engine/dmft_search/static
                <Directory /var/www/dmft_search_engine/dmft_search/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /files /var/www/dmft_search_engine/files/$
                <Directory /var/www/dmft_search_engine/files/>$
                        Order allow,deny
                        Allow from all
                </Directory>

                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

请帮助我。我还在.conf文件中添加了/files的别名。 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

问题是应用程序在根目录的上下文中运行 所以正确的路径应该是:

with  open('var/www/html/dmft_search_engine/files/filesystem/filesystem.pickle', 'rb') as handle:
        filesystem = pickle.load(handle)