码迷,mamicode.com
首页 > Web开发 > 详细

Nginx+uwsgi+web.py配置

时间:2017-05-20 23:40:37      阅读:329      评论:0      收藏:0      [点我收藏+]

标签:global   lob   down   thread   cat   icon   否则   dir   return   

遇坑的同鞋可以留意一下

操作系统:Centos7

准备文件:
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.gz


1、安装Python
configure注意带参数--with-zlib,否则uwsgi会报错
tar -zxvf Python-2.7.13.tgz
cd Python-2.7.13
./configure --with-zlib
make
make install
make clean

python --version 可以查看版本
修改版本会导致一些小问题,可以尝试修改#!/usr/bin/python为#!/usr/bin/python2.7

 

2、安装配置nginx
安装没什么特别的
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
./configure
make
make install
make clean

配置
如果没有自定义安装路径
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会处理这事

启动nginx
/usr/local/nginx/sbin/nginx
可以带配置文件,默认用/usr/local/nginx/conf/nginx.conf

试着访问一下x.x.x.x:80与x.x.x.x:2001


3、写一个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.py


4、安装配置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

在记事本中写了贴过来,格式有点问题,懒得改了

Nginx+uwsgi+web.py配置

标签:global   lob   down   thread   cat   icon   否则   dir   return   

原文地址:http://www.cnblogs.com/googlez/p/6883488.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!