在 apache 上部署烧瓶
deploy flask on apache
尝试执行此处描述的操作: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 直接 运行 没问题
有什么建议吗??
我认为您可能安装了错误的 mod_wsgi 版本。
您应该安装 python3
的版本
尝试执行此处描述的操作: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 直接 运行 没问题
有什么建议吗??
我认为您可能安装了错误的 mod_wsgi 版本。 您应该安装 python3
的版本