LinMinquan's Blog

Experience technology to change life

install PyCrypto on Windows

Environment: Python 2.7 My default python environment is python 3.4, and I create a Virtualenv of python 2.7, when I try to install PyCrypto, it return some error. I google and get a answer, I need to install prebuild binaries of PyCrypto, below is the page with those binaries for windows http://www.voidspace.org.uk/python/modules.shtml#pycrypto what I learned is to install in virtualenv  Reference: https://stackoverflow.com/questions/11405549/how-do-i-install-pycrypto-on-windows Read more →

Invalid HTTP_HOST header Django

环境:Centos, Django 1.11.4, 在运行Django Demo时的错误,运行是以监听所有IP的方式 报的错是 Invalid HTTP_HOST header Django. You may need to add u’xxx.xxx.com’ to ALLOWED_HOSTS. 解决办法是在Setting.py中,将u’xxx.xxx.com’(你的域名)加入到ALLOWED_HOSTS中,也把本地的ip也加进去。查了下官方文档,说是为了防止HTTP Host header attacks。   Read more →

Centos 6 Supervisor 开机启动

环境:阿里云Centos 6,Python ,Flask,Gunicorn,Supervisor,Nginx 参考资料: 链接1:centos下通过gunicorn+nginx+supervisor部署Flask项目 链接2:进程管理工具supervisor的使用注意事项 链接3:Setting Up Python and Supervisor on CentOS 链接4:supervisor+gunicorn部署python web项目 链接5:How to control your deamon with Supervisord (On CentOS) 1、supervisor是否要在虚拟环境中安装? 我想了想觉得应该是得在系统中安装。 2、supervisor的配置文件放在哪呢? 原本是放在每个项目的虚拟环境目录下,最佳实践(参考链接3,链接4)是在/etc/目录下建个默认的配置文件 echo_supervisord_conf > supervisord.conf 然后编辑这个配置文件,在最后让这个配置文件include指定目录下的配置文件 [include] files = /etc/supervisord.d/*.conf supervisord.d这个目录也是得自己新建,mkdir /etc/supervisord.d/ 然后再在/etc/supervisord.d/目录里放置所有的supervisor的配置文件。 3、怎样让Centos开机时就让supervisor启动这些配置文件呢? vi /etc/rc.d/rc.local 在rc.local里直接写 supervisord -c /etc/supervisord.conf 还不行,还得写全supervisord所在的路径。我这里也让nginx开机启动了。 Read more →

Python Flask Gunicorn Nginx CentOS Deploy SSL Https 多个App 部署

Centos 6,Python 2.7,阿里云ECS, 参考文章: 链接1:centos下通过gunicorn+nginx+supervisor部署Flask项目 链接2:Flask+Gunicorn+Nginx配置多个app 链接3:Virtual Hosts on nginx (CSC309) 我的需求是想在阿里云(Centos)上部署Flask的App,当然我想部署多个App在上面,另外我还会部署https。 链接1的文章写得特别好,但我需要部署https,这个是需要要nginx里配置的。我之前的部署方案也可以支持https,但据说会不稳定,方法是 Python Flask 支持 https Let’s Encrypt 。 nginx的坑。刚开始用nginx时,会发现它有很多个配置文件,网上不同的教程打开的配置文件都不一样,不同操作系统的配置文件目录也可能不同。真是非常崩溃。但后面也很好理解,它其实有一个主的配置文件,主的配置文件里可以包含其它的配置文件,这样它就把配置不同功能的配置文件分开了,比如说有专门配置ssl的配置文件ssl.conf。这样可以减少因为配置错误导致整体功能不可用的情况,单个配置文件错误的话至少只有相应的功能不可用。 其实你启动nginx后,在浏览器中进入nginx的默认页面,它就告诉你了它的配置文件在哪,Centos中是在 /etc/nginx/nginx.conf ,打开这个配置文件,你会注意到它里面有 include 这个词,这个是用于去包含其它目录下的配置文件。 配置https的证书我是在 sslforfree.com 上搞的,用的是Let’s Encrypt 的免费证书。 vi /etc/nginx/conf.d/ssl.conf 上面是我的配置。 测试时用 https://xx.example.com/test ,主要是指定证书,其它的ssl配置我都默认。我加了个ssl on 。 在做多app配置时我遇到一个问题,“ location / ”时可以,但“location /test”时不行(报404错误),解决这个办法请参考链接3。原因是nginx把 /test 这个发给Flask App,但我的Flask App里没有处理这个路由,所以报错了。 Read more →

terminal vi tab 4 spaces 空格

在命令行下,用vi来写代码时,按tab是8个空格,我不确定是否所有vi默认都是8个空格。我是在Mac terminal下发现有这个问题的。解决办法google “vi tab 4 spaces”一下就出来了。按ESC后输入 :set tabstop=4 后回车就可以了。 Read more →

Python Flask 支持 https Let’s Encrypt

有个小的用Flask写的Python程序需要支持https,证书用免费的Let’s Encrypt,在sslforfree.com上输入域名,获得证书。验证域名我用的是在vps上简单搭个ngnix来上传文件验证。 web server用的是Flask的werkzeug内置的server,配置ssl参考下面的链接 https://stackoverflow.com/questions/28579142/attributeerror-context-object-has-no-attribute-wrap-socket/28590266#28590266 http://werkzeug.pocoo.org/docs/0.12/serving/ 只需要多加两行代码即可 sslforfree中申请后下载得到的压缩包中包含certificate.crt,private.key,ca_bundle.crt。 怎么判断是否我们的Python程序的证书是否有效呢? 可以用chrome 60版本来判断。下面链接教怎么在cheome 60中查看证书。 https://www.ghacks.net/2017/07/27/configure-google-chrome-to-display-certificates-directly/ 这样就可以在chrome中访问某个get接口, 然后就可以查看证书的信息了。   Read more →

command ‘cc’ failed with exit status 69

Environment:Mac OS 10.12.2, Python 2.7.10 On terminal and use pip to install mysql-python (virtualenv is activate), but it get a error command ‘cc’ failed with exit status 69 reference link: http://stackoverflow.com/questions/19769648/cant-install-discount-with-pip-error-command-cc-failed-with-exit-status-1 I need to use xcode-select to install Xcode Command Line Tools Read more →

error: command ‘gcc’ failed with exit status 1

环境:CentOS 6.8, python 2.6.6, virtualenv 15.1.0 我是在virtualenv里,想要在里面安装mysql-python,但老报错 参考文章:http://blog.csdn.net/fenglifeng1987/article/details/38057193退出virtualenv 然后输入以下命令 不过这三个东西分别是什么用途呢? Read more →