1.配置好apache跟wsgi,然后通过pip将项目需要的依赖库进行安装,或者通过依赖文件一次性安装。
2.然后在/etc/apache2/sites-available下创建一个虚拟节点,
<VirtualHost *:80> ServerName 115.29.xx.xx ServerAlias xxxxxxxServer ServerAdmin jeff.yxj@foxmail.com ErrorLog "/home/log/pyServer/error.err" CustomLog "/home/log/pyServer/acc.access" common Alias /static/ /resource/img/ <Directory /resource/img/> Require all granted </Directory> WSGIScriptAlias / /Your/Project/app.wsgi WSGIApplicationGroup %{GLOBAL} <Directory
/Your/Project/
>AllowOverride All Require all granted<Files wsgi.py>Require all granted</Files> </Directory></VirtualHost>上面Require all granted之类的是apache2.4+的写法,apache2.2+需要使用另一种写法,ServerName是确定是不是这个节点处理请求的判断条件,可以是ip也可以是域名,这里我直接先用ip。static目录的别名是直接映射本地资源的,用来直接供用户请求服务器图片之类的资源使用的。
3.写完虚拟节点之后使用sudo a2ensite filename激活刚创建的虚拟节点,filename是刚才创建的文件的文件名,重启apache2生效。
4.然后发现mysql还没安装,然后使用apt-get安装下mysql,然后安装openssh,vsftpd用于ssh访问跟ftp访问。安装好后通过xftp这个软件将需要的数据传到ubuntu中,然后通过navicat ssh连接到ubuntu创建数据库,然后将测试时生成的数据库生成sql文件在ubuntu中执行创建所有表。
5.flask 的app.wsgi遇到找不到我们添加的项目模块的问题,按官网的说明在系统中加入我们的项目模块即可。
app.wsgi:
import sys sys.path.append('/Your/Project') from Project import app as application
6.然后重启apache,window电脑访问没有问题。