CentOS下Nginx+fastcgi+python3搭建web.py服务环境
来源:互联网 发布:linux 执行lua脚本 编辑:程序博客网 时间:2024/04/29 11:32
我的系统环境是CentOS release 6.6(Final)
环境依赖软件包
1、python32、Nginx1.4(需要包含fastcgi和rewrite模块)
3、web.py-python3(https://github.com/webpy/webpy/tree/python3)
4、Spawn-fcgi 1.6.3
5、Flup6
软件包安装
python3.6安装
[root@localhost home]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
[root@localhost home]# tar xJf Python-3.6.1.tar.xz
[root@localhost Python-3.6.1]# cd Python-3.6.1.tar.xz
[root@localhost Python-3.6.1]# ./configure --prefix=/usr/local/python3 && make && make install
#创建软连接
[root@localhost Python-3.6.1]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@localhost Python-3.6.1]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
可以参考CentOS6.6环境中安装Nginx详细过程笔记博客文章
安装spawn-fcgi
[root@localhost home]# wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
[root@localhost home]# tar zxvf spawn-fcgi-1.6.3.tar.gz
[root@localhost spawn-fcgi-1.6.3]# ./configure && make && make install
安装flup6
[root@localhost ~]# pip3 install flup6
安装web.py
[root@localhost home]# wget https://github.com/webpy/webpy/archive/python3.zip
[root@localhost home]# unzip webpy-python3.zip
[root@localhost home]# cd webpy-python3
[root@localhost webpy-python3]# python3 setup.py install
配置
Nginx配置文件如下:
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name pw.com; root /home/www/test; location / { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_pass 127.0.0.1:9002; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /static/ { if (-f $request_filename) { rewrite ^/static/(.*)$ /static/$1 break; } } }}在/home/www/demo目录下创建index.py
注意: 需要给代码设置执行权限,chmod +x index.py。
#!/usr/bin/env python3# -*- coding: utf-8 -*-import weburls = ("/.*", "hello")app = web.application(urls, globals())class hello: def GET(self): return 'Hello, world!'if __name__ == "__main__": web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr) app.run()
软件启动
Nginx启动
[root@localhost ~]# /usr/local/nginx/nginx
[root@localhost ~]# /usr/local/nginx/nginx -s reload #重启nginx配置
[root@localhost ~]# /usr/local/nginx/nginx -s stop #停止nginx
Spawn-fcgi启动
注意:你可以随意填写地址和端口信息,但是一定需要和Nginx配置文件相匹配
[root@localhost ~]# spawn-fcgi -d /home/www/demo -f /home/www/demo/index.py -a 127.0.0.1 -p 9002
[root@localhost ~]# kill `pgrep -f "python3 /home/www/demo/index.py"` #关闭进程
测试
[root@localhost ~]# curl localhost
如果打印“hello world!”则表示环境搭建成功
阅读全文
0 0
- CentOS下Nginx+fastcgi+python3搭建web.py服务环境
- CentOS下Nginx+fastcgi+python2搭建web.py服务环境
- Windows下nginx+web.py+fastcgi服务搭建
- Webpy + Nginx with FastCGI搭建Web.py
- Webpy + Nginx with FastCGI搭建Web.py
- CentOS下配置python3+flask的web服务环境
- Windows 下以 nginx + fastcgi 运行 Django 或 web.py
- linux下nginx+python+fastcgi部署总结(web.py版)
- CmsTop 大众版运行环境搭建 (CentOS+Nginx+PHP FastCGI)
- Linux下搭建基于Nginx+FastCGI+Flup+Webpy+Cheetah的Python Web环境
- nginx+fastcgi+c++/php搭建web服务
- Nginx+PHP(FastCGI)环境搭建
- nginx+python+fastcgi环境搭建
- linux下nginx+php(fastcgi)web服务器搭建
- CentOS+nginx+Django+Postgresql web环境搭建
- Centos下通过virtualenv工具配置python3+flask的web服务环境
- 基于CentOS 7 web服务环境搭建(包含JDK+Nginx+Tomcat+Mysql+Redis)
- centos 6.5下搭建hhvm+nginx环境
- 实战Java高并发程序设计-06 Java并发包并发集合
- [论文学习]Private traits and attributes are predictable from digital records of human behavior
- 获取XHR 兼容所有
- UVA 11987 Almost Union-Find [并查集]
- Bootstrap学习(第三节)
- CentOS下Nginx+fastcgi+python3搭建web.py服务环境
- Spring源代码解析(收藏)
- C语言(一):愉快的开始
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛 M SHUOJ 422 风力观测
- 用REDIS实现分布式缓存
- Spring-BeanFactory解读
- 消息队列使用的四种场景介绍
- IDEA初次安装后优化修改内容
- 流程的Python 第六章:使用一等函数来设计模式