先照着这里的步骤安装apache和mod_wsgi: my.oschina.net/wuliong/blog/1546303
apache会安装在 /usr/local/apache/bin/apachectl
mod_wsgi安装在/usr/local/apache/modules/mod_wsgi.so
apache配置文件在:/etc/httpd/httpd.conf 和 /etc/httpd/extra/httpd-vhosts.conf
创建一个helloworld项目:
mkdir /home/myawesomeapp
cd /home/myawesomeapp
touch run.wsgi
touch helloworld.py
helloworld.py 内容为
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
run.wsgi 内容为
import sys
sys.path.insert(0, '/home/myawesomeapp')
from helloworld import app as application
然后修改配置文件 httpd.conf,在文件末尾添加
PidFile "/var/run/httpd.pid"
LoadModule wsgi_module modules/mod_wsgi.so
修改httpd-vhosts.conf,添加
Listen 5000
<VirtualHost *:5000>
DocumentRoot /home/myawesomeapp
WSGIDaemonProcess helloworld user=daemon group=daemon threads=5 python-path=/opt/python35/bin
WSGIScriptAlias / /home/myawesomeapp/run.wsgi
ErrorLog "/home/myawesomeapp/logs/error.log"
CustomLog "/home/myawesomeapp/logs/access.log" common
<Directory "/home/myawesomeapp">
Require all granted
AllowOverride All
WSGIScriptReloading On
</Directory>
</VirtualHost>
启动apache
apachectl start
命令行输入 netstat -tnlp 查看5000端口是否开通。
然后在浏览器打开 <阿里云公网ip地址>:5000