我正在尝试使用 apache 和 mod_wsgi 部署 Flask 应用。我一直在遵循以下指示这里。该网站上简单的 hello-world 示例运行完美。
当我尝试替换我自己的 Flask 应用程序时,我得到了一个500 Internal Server Error
。这是来自 apache 日志的输出:
[Wed Oct 02 14:50:26 2013] [info] [client 68.184.201.104] mod_wsgi (pid=4881, process='', application='toptencrop.com|'): Loading WSGI script '/var/www/top_ten_crop/crop.wsgi'.
[Wed Oct 02 14:50:26 2013] [error] [client 68.184.201.104] mod_wsgi (pid=4881): Target WSGI script '/var/www/top_ten_crop/crop.wsgi' cannot be loaded as Python module.
[Wed Oct 02 14:50:26 2013] [error] [client 68.184.201.104] mod_wsgi (pid=4881): Exception occurred processing WSGI script '/var/www/top_ten_crop/crop.wsgi'.
[Wed Oct 02 14:50:26 2013] [error] [client 68.184.201.104] Traceback (most recent call last):
[Wed Oct 02 14:50:26 2013] [error] [client 68.184.201.104] File "/var/www/top_ten_crop/crop.wsgi", line 9, in <module>
[Wed Oct 02 14:50:26 2013] [error] [client 68.184.201.104] from crop import app as application
[Wed Oct 02 14:50:26 2013] [error] [client 68.184.201.104] ImportError: No module named crop
我尝试过的事情
- 我已将权限设置为 0644
- 重新编译 mod_wsgi 以确保它是同一版本的 python
- 确保如果我进入该
sys.path.insert(0,'/var/www/top_ten_crop')
行,我可以从任何地方导入我的应用程序。 - 一遍又一遍地检查配置文件中的所有路径。
我将非常感激任何关于尝试的建议。以下是相关文件:
/var/www/top_ten_crop/crop.wsgi:
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,'/var/www/top_ten_crop')
from crop import app as application
application.secret_key = 'secret'```
/etc/apache2/sites-available/top_ten_crop
<VirtualHost *:80>
ServerName toptencrop.com
ServerAdmin [email protected]
WSGIScriptAlias / /var/www/top_ten_crop/crop.wsgi
WSGIPassAuthorization On
<Directory /var/www/top_ten_crop/crop>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/top_ten_crop/crop/static
<Directory /var/www/top_ten_crop/crop/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
输出tree
top_ten_crop/
├── bootstrap.sh
├── config_files
│ ├── celeryd
│ └── mod_wsgi_config
├── crop
│ ├── celery.py
│ ├── constants.py
│ ├── forms.py
│ ├── helpers.py
│ ├── __init__.py
│ ├── models.py
│ ├── mturkcore.py
│ ├── mturk.py
│ ├── static
│ │ ├── css
│ │ │ ├── bootstrap.css
│ │ │ ├── bootstrap.min.css
│ │ │ ├── bootstrap-responsive.css
│ │ │ ├── bootstrap-responsive.min.css
│ │ │ ├── Jcrop.gif
│ │ │ ├── jquery.Jcrop.css
│ │ │ ├── jquery.Jcrop.min.css
│ │ │ └── main.css
│ │ ├── img
│ │ │ ├── glyphicons-halflings.png
│ │ │ ├── glyphicons-halflings-white.png
│ │ │ └── worker_id.jpg
│ │ └── js
│ │ ├── bootstrap.js
│ │ ├── bootstrap.min.js
│ │ ├── jquery.color.js
│ │ ├── jquery.Jcrop.js
│ │ ├── jquery.Jcrop.min.js
│ │ └── jquery.min.js
│ ├── tasks.py
│ ├── templates
│ │ ├── 404.html
│ │ ├── base.html
│ │ ├── boot.html
│ │ ├── example.html
│ │ ├── helpers.html
│ │ ├── images.html
│ │ ├── image_status.html
│ │ ├── job.html
│ │ ├── list_comments.html
│ │ ├── list_examples.html
│ │ ├── list_users.html
│ │ ├── login.html
│ │ ├── new_example.html
│ │ ├── register.html
│ │ ├── review_crop.html
│ │ ├── review_validation.html
│ │ ├── selection_job.html
│ │ └── validation_job.html
│ └── views.py
├── crop.wsgi
├── db_create.py
├── interactive_bootstrap.py
├── README.md
├── runserver.py
├── selection_hit.html
├── top10-crop.log
├── Vagrantfile
└── validation_hit.html
7 directories, 57 files