当我从某个位置直接加载我的课程时,我可以加载它。
>>> import sys
>>> sys.path.append('/path/to/my/flask/application')
>>> from myfile import app as application
>>>
现在来自wsgi,当我做同样的事情时......它没有加载。
[Sat Aug 19 07:41:18 2017] [info] mod_wsgi (pid=29177): Imported 'mod_wsgi'.
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] mod_wsgi (pid=29172): Target WSGI script '/var/www/flask-prod/webtool.wsgi' cannot be loaded as Python module.
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] mod_wsgi (pid=29172): Exception occurred processing WSGI script '/var/www/flask-prod/webtool.wsgi'.
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] Traceback (most recent call last):
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] File "/var/www/flask-prod/webtool.wsgi", line 6, in <module>
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] from myfile import app as application
[Sat Aug 19 07:41:24 2017] [error] [client 129.91.63.143] ImportError: No module named myfile
下面的wsgi虚拟主机配置:
WSGIPythonHome /pathto/condadir
WSGIPythonPath /pathto/condadir/lib/python2.7
<virtualhost *:80>
ServerName myhost.example.com
WSGIDaemonProcess webtool user=apache group=root threads=5 home=/var/www/flask-prod/
WSGIScriptAlias / /var/www/flask-prod/webtool.wsgi
<directory /var/www/flask-prod>
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order allow,deny
Allow from all
</directory>
</virtualhost>
以下是wsgi文件。
#!/pathto/condadir/bin/python
import sys
sys.path.append('/path/to/my/flask/application')
from myfile import app as application
$ df -hP
/dev/xvda1 494M 29M 440M 7% /boot
tmpfs 5.0G 0 5.0G 0% /dev/shm
/dev/xvdc1 50G 3.2G 44G 7% /path
/dev/mapper/vg_apol-lv_var 1.5G 164M 1.3G 12% /var
$ ls -lrt /path/to/my/flask/
-rwxrwx--- 1 root root 109 Aug 9 11:16 README
drwxrwx--- 4 root root 4096 Aug 19 08:24 application
-rw------- 1 root root 0 Aug 19 08:25 __init__.py
$ ls -lrt /path/to/my/flask/application
-rwxrwx--- 1 root root 23 Jun 4 05:19 __init__.py
drwxrwx--- 6 root root 4096 Aug 7 15:24 static
-rwxrwx--- 1 root root 7168 Aug 9 11:45 users_sqlite.db
-rwxrwx--- 1 root root 9670 Aug 9 12:06 myfile.py
drwxrwx--- 5 root root 4096 Aug 10 14:50 templates
-rwxrwx--- 1 root root 448 Aug 10 14:51 myfile.pyc
$ pwd
/var/www
$ ls -ld flask-prod
drwxr-xr-x 2 root root 4096 Aug 19 08:21 flask-prod
$ ls -rlt flask-prod/
total 28
-rw------- 1 root root 0 Aug 18 15:54 __init__.py
-rwxr-xr-x 1 root root 258 Aug 19 08:21 webtool.wsgi