Windows环境下flask+Apache+mod_wsgi部署及爬坑
文章目录
安装python
下载相应的安装包python-3.6.5-amd64.exe
,直接双击打开即可一步步安装,非常简单
Windows 环境使用virtualenv和virtualenvwrapper
- 环境搭建
- 安装virtualenv:
pip install virtualenv
- 安装virtualenvwrapper:
pip install virtualenvwrapper-win
- 配置环境变量:打开系统环境变量,添加:
WORKON_HOME=C:\virtualenvs 注意这个目录是虚拟环境存放的目录
- 配置完环境变量,一定要重启cmd窗口,要不然环境变量不生效。
- 安装virtualenv:
- 常用命令:
- 新建虚拟环境:
mkvirtualenv BoyPy36
- 查看所有虚拟环境:
workon
- 进入虚拟环境:
workon BoyPy36
- 退出虚拟环境:进入到虚拟环境的目录,例如:C:\virtualenvs\LibraFlaskPy36\Scripts, 输入:
deactivate
- 激活虚拟环境:进入到虚拟环境的目录,例如:C
:\virtualenvs\LibraFlaskPy36\Scripts 输入:activate.bat
- 新建虚拟环境:
安装mod_wsgi
在这个网站 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 上找到编译好的包,进入到安装包的路径,输入如下命令,进行安装
pip +ap24vc14-cp36-cp36m-win_amd64.whl
安装nginx
本来想安装nginx来着,后来大量查阅资料,发现windows下还是Apache用着顺手,以下安装nginx步骤仅供参考,后面会详细介绍Apache的安装和配置
- 下载相应的安装包:http://nginx.org/en/download.html
- 输入如下命令:
cd c:\ .zip cd nginx- start nginx
- 运行tasklist查看运行进程:
C:\nginx->tasklist /fi "imagename eq nginx.exe" Image Name PID Session Name Session# Mem Usage =============== ======== ============== ========== ============ nginx.exe Console K nginx.exe Console K
- 在浏览器输入:
http://localhost
,显示欢迎页,表示启动成功 - 常用相关命令:
nginx -s stop fast shutdown nginx -s quit graceful shutdown nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes nginx -s reopen re-opening log files
安装Apache
- 去官网 http://httpd.apache.org/download.cgi 下载相应的安装包,解压,打开cmd终端,进入到Apache/bin目录,输入如下命令,不报错表明安装成功
httpd -k install
- 双击ApacheMonitor.exe,打开服务管理UI界面,可以对Apache服务进行管理。
- 也可以用命令对Apache服务进行管理
httpd -k [start|stop|restart] # 用来 启动|停止|重启 服务
- 如果有报错,可以到Apache/logs目录下查看日志:error.log,看相关的报错信息,再进行具体问题具体解决。
遇到的坑
安装Apache遇到的坑
- 配置apache,在Apache24/conf/httpd.conf的最后添加上如下的配置,使用
mod_wsgi-express module-config > myconfig.txt
,可以得到 mod_uwsgi 配置:################################################################################ # mod_wsgi 配置 LoadFile "c:/python36/python36.dll" LoadModule wsgi_module "c:/virtualenvs/libraflaskpy36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd" WSGIPythonHome "c:/virtualenvs/libraflaskpy36" # 参考:https://dormousehole.readthedocs.io/en/latest/deploying/mod_wsgi.html <VirtualHost *> ServerName # 这里我少写了80端口,坑死了 WSGIScriptAlias / C:\tools\ZLflask\Libra.wsgi <Directory C:\tools\ZLflask> # Order deny,allow # Allow from all Require all granted </Directory> </VirtualHost>
中间有一段配置也要改,这里坑死,搞了好久:
<Directory /> #AllowOverride none #Require all denied AllowOverride All # 改成这样的配置,为了让别人访问到这个IP地址 Require all granted </Directory> ... ServerName # 修改ip地址
修改证书的配置,去掉ssl认证,因为是公司内部使用,不需要绑定域名和认证,将下面这句话注释掉:
LoadModule ssl_module modules/mod_ssl.so
- 新建app.wsgi文件,写上如下代码:
# 添加虚拟环境的路径 activate_this = 'C:\\virtualenvs\\LibraFlaskPy36\\Scripts\\activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this))
在这里重点说明下,配置的时候,一直报错:
[Tue Oct ::] [wsgi:error] [pid :tid ] [client ] Traceback (most recent call last):\r, referer: http://192.168.6.27/index [Tue Oct ::] [wsgi:error] [pid :tid ] [client ] File , in <module>\r, referer: http://192.168.6.27/index [Tue Oct ::] [wsgi:error] [pid :tid ] [client ] from app import app as application\r, referer: http://192.168.6.27/index [Tue Oct ::] [wsgi:error] [pid :tid ] [client ] ModuleNotFoundError: No module named 'app'\r, referer: http://192.168.6.27/index
后来找了好久,加上下面的2行代码,成功了:
import sys sys.path.insert(0, "C:\\tools\\ZLflask")
app.wsgi 文件的全部代码:
# 添加虚拟环境的路径 activate_this = 'C:\\virtualenvs\\LibraFlaskPy36\\Scripts\\activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this)) # 将项目的路径添加到系统中,不然就会报错 import sys sys.path.insert(0, "C:\\tools\\ZLflask") from app import app as application
安装mod_uwsgi的坑
安装的时候一直报这个错:
Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Users\Dell\AppData\Local\Temp\pip-install-pnicet59\mod-wsgi\setup.py", line 158, in <module> raise RuntimeError('No Apache installation can be found. Set the ' RuntimeError: No Apache installation can be found. Set the MOD_WSGI_APACHE_ROOTDIR environment to its location. ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in C:\Users\Dell\AppData\Local\Temp\pip-install-pnicet59\mod-wsgi\
解决办法:
在这个网站 https://www.lfd.uci.edu/~gohlke/pythonlibs/上找到编译好的包进行安装,重启Nginx好了。
洛水之风的公众号
Windows环境下flask+Apache+mod_wsgi部署及爬坑的更多相关文章
- Windows环境下使用Apache+mod_wsgi部署webpy
1.安装Python和Apache. 2.安装mod_wsgi后获得wsgi.so,并将wsgi.so放到Apache的modules文件夹下. 3.安装webpy. 4.打开httpd.conf(在 ...
- windows环境下,apache虚拟主机配置
在windows环境下,apache从配置文件的相关配置: Windows 是市场占有率最高的 PC 操作系统, 也是很多人的开发环境. 其 VirtualHost 配置方法与 Linux 上有些差异 ...
- Windows环境下,将Django部署到Apache Web Server
在Windows上部署Django(用mod_wsgi)会出现各种奇怪的问题,现简单记录下配置过程及遇到的错误及解决方法. 环境搭建 ...
- Windows环境下 PHP+Apache+Mysql配置
网上关于这种搭配的配置有许多许多,但是不知道大家有否碰到这么一个问题,就是做好的PHP程序(内含访问mysql数据库的操作)发布到Apache服务器上之后, 运行程序,提示未找到数据库函数. 仔细检查 ...
- Apache+Tomcat+jk windows环境下的集群部署
记一次在Windows服务器上搭建apatch+tomcat+jk的集群搭建过程,其中也遇到了很多问题,总结一下. 一.准备工作 1.apache-tomcat-7.0.88 2.Apche http ...
- PHP基础 windows环境下安装Apache Mysql PHP
本篇文章主要是讲一下我自己安装wamp环境的一些步骤和见解,前方多图预警,慎入!!!!! PHP运行环境 : Linux下的三种安装方式:源码包安装.rpm包安装.集成环境安装(lnmp) wind ...
- Windows环境下使用Apache+mod
1.安装Python和Apache. 2.安装mod_wsgi后获得wsgi.so,并将wsgi.so放到Apache的modules文件夹下. 3.安装webpy. 4.打开httpd.conf(在 ...
- Windows环境下实现Jenkins自动化部署
详见:https://blog.csdn.net/Try_harder_every_day/article/details/79170065 Jenkins自动化部署: 几条具体的思路:1.开发人员将 ...
- windows环境下Git的安装部署
一.获取安装包 百度搜索“git”,或者访问git官网:https://git-scm.com/,在首页中点击“downloads”进入下载页面 点击“windows”,获取安装包 二.安装部署 双击 ...
随机推荐
- 浅谈java缓存
java中要用到缓存的地方很多,首当其冲的就是持久层缓存,针对持久层谈一下: 要实现java缓存有很多种方式,最简单的无非就是static HashMap,这个显然是基于内存缓存,一个map就可以搞定 ...
- E - 吃糖
题目描述: 某人买了n兜糖果,第i兜有Ai块糖.此人把所有这些糖果用一个数字标记起来:他这样标记这些糖,第一袋糖用用数字1到A1,第二袋糖用数字A1+1到A1+A2,如此类推.如果还没明白看样例可以更 ...
- ZOJ 1860:Dog & Gopher
Dog & Gopher Time Limit: 2 Seconds Memory Limit: 65536 KB A large field has a dog and a gop ...
- go语言笔记——切片底层本质是共享数组内存!!!绝对不要用指针指向 slice切片本身已经是一个引用类型就是指针
切片 切片(slice)是对数组一个连续片段的引用(该数组我们称之为相关数组,通常是匿名的),所以切片是一个引用类型(因此更类似于 C/C++ 中的数组类型,或者 Python 中的 list 类型) ...
- 【转载】HashMap底层实现原理及面试问题
①HashMap的工作原理 HashMap基于hashing原理,我们通过put()和get()方法储存和获取对象.当我们将键值对传递给put()方法时,它调用键对象的hashCode()方法来计算h ...
- django - request.POST和request.body获取值时出现的情况
django request.POST / request.body 当request.POST没有值 需要考虑下面两个要求 1.如果请求头中的: Content-Type: application/ ...
- J20170916-hm
スタイルシート 样式表 シール 封条 シート 纸片 マニフェスト 货单(Rails) ダイジェスト 消化,(Rails 附加哈希值) インタプリタ n. 解释者; 口译译员; [军事] 判读员; [自 ...
- Rails5 Route Document
创建: 2017/06/29 完成: 2017/06/29 更新: 2017/06/30 最开头的有效路径展示补充网页版 更新: 2017/07/21 修正错别字 更新: 2017/09/02 增加m ...
- Codeforces 769D
太久没写搜索因为递归边界问题卡了很久.. 题意:定义k-interesting:如果两个数的二进制形式有k位不相同,则称之为k-interesting.给出n和k,输入n个大小在[0,10000]之间 ...
- python中的深拷贝和浅拷贝(面试题)
一.浅拷贝 定义:浅拷贝只是对另外一个变量的内存地址的拷贝,这两个变量指向同一个内存地址的变量值. 浅拷贝的特点: 公用一个值: 这两个变量的内存地址一样: 对其中一个变量的值改变,另外一个变量的值也 ...