尝试做这里描述的内容:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps 在这里:http://flask.pocoo.org/docs/0.10/deploying/mod_wsgi/#configuring-apache
但无论我尝试什么,我都会在apache错误日志中找到这些错误:
[Sun Mar 22 12:25:45 2015] [info] [client 192.168.2.10] mod_wsgi (pid=4842, process='', application='192.168.2.32|'): Loading WSGI script '/var/www/hello_world/hello_world.wsgi'.
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] mod_wsgi (pid=4842): Target WSGI script '/var/www/hello_world/hello_world.wsgi' cannot be loaded as Python module.
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] mod_wsgi (pid=4842): Exception occurred processing WSGI script '/var/www/hello_world/hello_world.wsgi'.
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] Traceback (most recent call last):
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] File "/var/www/hello_world/hello_world.wsgi", line 12, in <module>
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] from hello_world import app as application
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] File "/var/www/hello_world/hello_world/__init__.py", line 1, in <module>
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] from flask import Flask
[Sun Mar 22 12:25:45 2015] [error] [client 192.168.2.10] ImportError: No module named flask
这是我的wsgi文件:
#!/usr/bin/python
import sys
import logging
activate_this = '/var/www/hello_world/hello_world/venv/bin/activate_this.py'
exec(open(activate_this).read())
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/hello_world/")
from hello_world import app as application
application.secret_key = 'bigsecret'
和我的 init .py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, I love Digital Ocean!"
if __name__ == "__main__":
app.run()
和我的虚拟主机文件:
<VirtualHost *:80>
ServerName 192.168.2.32
ServerAdmin admin@mywebsite.com
WSGIScriptAlias / /var/www/hello_world/hello_world.wsgi
<Directory /var/www/hello_world/hello_world/>
Order allow,deny
Allow from all
</Directory>
Alias /static /var/www/hello_world/hello_world/static
<Directory /var/www/hello_world/hello_world/static/>
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
我把所有东西安装在一个venv中。当我直接运行 init .py时,它运行良好
有什么建议吗?
答案 0 :(得分:0)
我认为您可能安装了错误版本的mod_wsgi。 你应该安装python3的版本