本文介绍在Linux使用Python+Nginx+web2py+uWSGI搭建一个web服务器的过程。

Python 2.7.11

解压安装包


tar -zxvf Python-2.7.11.tgz
cd Python-2.7.11
yum install sqlite-devel
./configure --enable-loadable-sqlite-extensions

会提示错误


Python build finished, but the necessary bits to build these modules were not found:
_ssl _tkinter bsddb185
bz2 dl imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

需要安装相应的依赖包


yum install openssl-devel

按照依赖包操作,具体可以参照这篇文档

继续安装


make
make install
rm /usr/bin/python
ln -s /usr/local/bin/python2.7 /usr/bin/python python
Python 2.7.11 (default, Feb 2 2016, 14:33:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

安装Nginx

tar -zxvf nginx-1.8.0.tar.gz
tar -xzvf zlib-1.2.8.tar.gz
tar -zxvf pcre-8.37.tar.gz
groupadd nginx
useradd nginx -g nginx
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-pcre=/opt/web/pcre-8.37 \
--with-zlib=/opt/web/zlib-1.2.8 \
--with-http_addition_module \
--with-http_realip_module
make
make install cd /usr/local/nginx/sbin
./nginx

安装uWSGI


tar -zxvf uwsgi-latest.tar.gz
cd uwsgi-2.0.12
python uwsgiconfig.py --build
cp uwsgi /usr/sbin

配置uWSGI

创建配置文件/etc/uwsgi/web2py.ini,并在配置文件中输入以下内容。


[uwsgi]
socket = 127.0.0.1:9090
pythonpath = /var/www/html/web2py/
mount = /=wsgihandler:application
processes = 4
master = true
harakiri = 60
reload-mercy = 8
cpu-affinity = 1
stats = /tmp/%n.stats.socket
max-requests = 5000
limit-as = 1024
reload-on-as = 256
reload-on-rss = 192
cron = 0 0 -1 -1 -1 python /var/www/html/web2py/web2py.py -Q -S welcome -M -R scripts/sessions2trash.py -A -o
no-orphans = true
chmod-socket = 666

创建uWSGI开关命令。


'#!/bin/sh
'# Autor: Nilton OS -- www.linuxpro.com.br
'#
'#
'### BEGIN INIT INFO
'# Provides: uwsgi
'# Required-Start: $syslog $remote_fs
'# Should-Start: $time ypbind smtp
'# Required-Stop: $syslog $remote_fs
'# Should-Stop: ypbind smtp
'# Default-Start: 3 5
'# Default-Stop: 0 1 2 6
'### END INIT INFO '# Source function library.
. /etc/rc.d/init.d/functions '# Check for missing binaries (stale symlinks should not happen)
UWSGI_BIN=`which uwsgi`
test -x $UWSGI_BIN || { echo "$UWSGI_BIN not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; } UWSGI_EMPEROR_MODE=true
UWSGI_VASSALS="/etc/uwsgi/"
UWSGI_OPTIONS="--enable-threads --logto /var/log/uwsgi/uwsgi.log"
lockfile=/var/lock/subsys/uwsgi UWSGI_OPTIONS="$UWSGI_OPTIONS --autoload" if [ "$UWSGI_EMPEROR_MODE" = "true" ] ; then
UWSGI_OPTIONS="$UWSGI_OPTIONS --emperor $UWSGI_VASSALS"
fi case "$1" in
start)
echo -n "Starting uWSGI "
daemon $UWSGI_BIN $UWSGI_OPTIONS &
;;
stop)
echo -n "Shutting down uWSGI "
killproc $UWSGI_BIN
;;
restart)
$0 stop
$0 start
;;
status)
echo -n "Checking for service uWSGI "
status $UWSGI_BIN
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
exit 0

根据上面的开关命令,还需要增加一个uWSGI的日志文件。


mkdir -p /var/log/uwsgi
touch /var/log/uwsgi/uwsgi.log

web2py安装

所谓的安装只需要将web2py的包解压到指定目录就可以,从官网可以下载二进制包。


mkdir /var/www/html
unzip web2py_src.zip
mv web2py/handlers/wsgihandler.py web2py/wsgihandler.py
chown -R nginx:nginx web2py
cd web2py
sudo -u nginx python -c "from gluon.main import save_password; save_password('password',443)"

配置NginX

增加一个server模块,监听80端口,将访问使用uWSGI转移到web2py。


server {
listen 80;
server_name YOUR_SERVER_FQDN; '#to enable correct use of response.static_version
location ~* /(\w+)/static(?:/_[\d]+\.[\d]+\.[\d]+)?/(.*)$ {
alias /var/www/html/web2py/applications/$1/static/$2;
expires max;
}
location / {
uwsgi_pass 127.0.0.1:9090;
uwsgi_pass unix:///var/www/html/web2py/logs/web2py.socket;
include /etc/nginx/uwsgi_params;
}
}

启动Nginx和uWSGI

注意:web2py本身不需要启动,只用被uWSGI被动调用即可。


/usr/local/nginx/sbin/nginx /etc/init.d/uwsgi start

以上执行完后,在浏览器访问服务器的IP地址,若需要以下页面则说明部署成功。

版权说明:camash原创,转载请注明出处 http://www.cnblogs.com/shenfeng/

--EOF--

在Linux上使用web2py_uwsgi_nginx搭建web服务器的更多相关文章

  1. 在Linux上用Apache搭建Git服务器

    在Linux上用Apache搭建Git服务器   最近在学Linux,终于在Linux上用Apache搭建起了Git服务器,在此记录一下. 服务器:阿里云服务器 Linux版本:CentOS 6.5 ...

  2. Windows&linux使用集成环境搭建 web 服务器

    文章更新于:2020-02-17 按照惯例,需要的文件附上链接放在文首 文件名:phpStudy_64.7z 文件大小:78.3 M 下载链接https://www.lanzous.com/i9c6l ...

  3. linux上nginx+apache 搭建 svn服务器

    众所周知,nginx目前是不支持svn的,并且由于机房网络只开了80和22(ssh)端口,所以这时候就没法单独在服务器上搭建apache+svn .所以就产生了 nginx + apache + sv ...

  4. Linux上rpm实战搭建FTP服务器

    1.检测是否已安装FTP服务 # rpm -qa|grep vsftpd 2.未安装ftp服务的前提进行使用rpm安装 # yum install vsftpd -y Loaded plugins: ...

  5. Linux上用nginx搭建RTMP服务器

    参考文章:https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.5 ...

  6. Mac上一条命令搭建web服务器

    实际测试工作中偶尔会需要搭建Web服务器环境,由于Mac OS X自带了Apache和PHP环境,只需要简单的启动就可以. 开启Apache 开启Web服务器的方法有两种(默认启动端口号是80): 打 ...

  7. 轻松使用Nginx搭建web服务器

    如果读者以前做过web开发的话,就应该知道如何去搭建一个web服务器来跑你的web站点,在windows下你可能会选择去用IIS,十分的快捷,在linux下,你可能首先会想到apache,“一哥”( ...

  8. CentOS 6.2下搭建Web服务器

    1Centos 6.2下搭建web服务器 如今,Linux在Web应用越来越广,许多企业都采用Linux来搭建Web服务器,这样即节省了购买正版软件的费用,而且还能够提高服务器的安全性. 之前我们介绍 ...

  9. Android手机用KSWEB搭建Web服务器成功安装WordPress

    之前部落分享的几个免费Web服务器软件都是用来安装在本地电脑上,搭建Apache.PhpMyAdmin.MySQL等网站运行环境,然后我们就可以在电脑上测试运行Wordpress.Discuz! 论坛 ...

随机推荐

  1. ASP.NET MVC 上传大文件时404

    前一段时间会员的上传组件改用FLASH的swfupload来上传,既能很友好的显示上传进度,又能完全满足大文件的上传. 后来服务器升级到windows 2008,改为IIS7后,上传文件一旦超过30M ...

  2. 53个要点提高PHP编程效率

    1.如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍. 2.$row[’id’] 的速度是$row[id]的7倍.3.echo 比 print 快,并且使用echo ...

  3. POJ 1068 Parencodings 模拟 难度:0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  4. POJ 1083 Moving Tables 思路 难度:0

    http://poj.org/problem?id=1083 这道题题意是有若干段线段,每次要求线段不重叠地取,问最少取多少次. 因为这些线段都是必须取的,所以需要让空隙最小 思路: 循环直到线段全部 ...

  5. 一模 (4) day2

    第一题: 题目大意:二进制数 n mod m 的结果是多少?  n 的长度(二进制数的位数)<=200 000:  m 的长度(二进制数的位数)<=20. 解题过程: 1.我的算法是直接高 ...

  6. 向MySql中插入中文时出现乱码

    这个因为字符集编码问题.在连接字符串中加上CharSet=gbk

  7. Java并发编程(二)线程任务的中断(interrupt)

    使用interrupt()中断线程 当一个线程运行时,另一个线程可以调用对应的Thread对象的interrupt()方法来中断它,该方法只是在目标线程中设置一个标志,表示它已经被中断,并立即返回. ...

  8. POJ 2992 求组合数的因子个数

    求C(n,k)的因子个数 C(n,k) = (n*(n-1)*...*(n-k+1))/(1*2*...*k) = p1^k1 * p2^k2 * ... * pt^kt 这里只要计算出分子中素数因子 ...

  9. 【kate总结】Matlab坐标轴问题

    [kate总结]Matlab坐标轴问题 总结而言 行óYó高ó垂直 列óXó宽ó水平 Maplab中存有2张图片 1.JPG 宽(列):320    高(行):482 在matlab中显示 2.JPG ...

  10. kali linux SET工具包

    尝试使用SET生成Teensy脚本是出现问题 1.出现错误 [!] Something went wrong, printing the error: [Errno 2] No such file o ...