遇坑的同鞋能够留意一下html
操做系统:Centos7python
准备文件:
Python-2.7.13.tgz
下载地址:https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz
nginx-1.12.0.tar.gz
下载地址:http://nginx.org/download/nginx-1.12.0.tar.gz
uwsgi-2.0.15.tar.gz
下载地址:https://projects.unbit.it/downloads/uwsgi-2.0.15.tar.gznginx
一、安装Python
configure注意带参数--with-zlib,不然uwsgi会报错
tar -zxvf Python-2.7.13.tgz
cd Python-2.7.13
./configure --with-zlib
make
make install
make cleanweb
python --version 能够查看版本
修改版本会致使一些小问题,能够尝试修改#!/usr/bin/python为#!/usr/bin/python2.7app
二、安装配置nginx
安装没什么特别的
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure
make
make install
make cleanpython2.7
配置
若是没有自定义安装路径
nginx.conf文件默认路径为/usr/local/nginx/conf/nginx.conf
若是用yum安装配置路径为/etc/nginx/nginx.conf
能够试着查找
find /|grep nginx.conf
whereis nginx
修改nginx.conf 文件,没必要担忧改坏了,同目录下还有个nginx.conf.default
若是80端口有其它用处,能够把listen 80;改为其它端口,避免冲突
内容不妨先仿着server再写一个server与原来的server保持并列,
server {
listen 2001;
server_name [::]:2001 localhost;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8080;
}
}
listen应该是监听,那么从外部访问应该访问2001端口
uwsgi_pass 127.0.0.1:8080;这句与proxy_pass看起来很像,向内转发数据,而且须要在8080端口上有监听,uwsgi会处理这事curl
启动nginx
/usr/local/nginx/sbin/nginx
能够带配置文件,默认用/usr/local/nginx/conf/nginx.confsocket
试着访问一下x.x.x.x:80与x.x.x.x:2001ui
三、写一个test.py
暂且放在/var/test/路径下
#!/usr/bin/python2.7
# -*- coding:utf-8 -*-
# test.py
import web
urls = (
'/', 'index'
)
class index:
def GET(self):
return 'Hello, world!'
app = web.application(urls,globals())
# app.run()
application = app.wsgifunc()
若是没有web模块能够先pip install web.py
试试会不会报错python code.pyurl
四、安装配置uwsgi
这里有更详细的说明
http://uwsgi-docs.readthedocs.io/en/latest/Install.html
tar -zxvf uwsgi-2.0.15.tar.gz
cd uwsgi-2.0.15
python uwsgiconfig.py --build
配置文件
支持多种格式,这里用ini
为code.py写一个配置文件test.uwsgi.ini
[uwsgi]
socket = 127.0.0.1:8080 #与nginx的uwsgi_pass对应
chdir = /var/test/
wsgi-file = test.py
processes = 4
threads = 2
stats = 127.0.0.1:2011
daemonize = ./uwsgi.log
启动
./uwsgi --wsgi-file test.uwsgi.ini
若是正常的话
curl x.x.x.x:2001
将会返回Hello,world
不然能够到uwsgi.log中查看错误信息
查看端口占用
lsof -i:80
在记事本中写了贴过来,格式有点问题,懒得改了