1.安装mod_wsgi:
sudo apt-get install libapache2-mod-wsgi python-dev2.启用mod_wsgi
sudo a2enmod wsgi3.创建Web应用的apache2配置文件
sudo vim /etc/apache2/sites-available/FlaskApp.conf
以下是YourApp.conf文件内容
<VirtualHost *:80> ServerName mywebsite.com ServerAdmin admin@mywebsite.com WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi <Directory /var/www/FlaskApp/FlaskApp/> Order allow,deny Allow from all </Directory> Alias /static /var/www/FlaskApp/FlaskApp/static <Directory /var/www/FlaskApp/FlaskApp/static/> Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>4.启用配置文件
sudo a2ensite FlaskApp
5.创建.wsgi文件
cd /var/www/FlaskApp sudo vim flaskapp.wsgiflaskapp.wsgi文件内容为:
#!/usr/bin/python import sys import logging logging.basicConfig(stream=sys.stderr) sys.path.insert(0,"/var/www/FlaskApp/") from FlaskApp import app as application application.secret_key = 'Add your secret key'现在你的工程目录应该是下面结构:
|--------FlaskApp |----------------FlaskApp |-----------------------static |-----------------------templates |-----------------------venv |-----------------------__init__.py |----------------flaskapp.wsgi6.重启服务器
service apache2 restart
注意事项:
*应用的启动模块名称必须是__init__.py
参考:https://www.digitalocean.com/community/tutorials/how-to-deploy-a-flask-application-on-an-ubuntu-vps