1、关闭SELINUX:
[root@PYTHON27 /]# vim /etc/selinux/config
将SELINUX=enforcing修改为SELINUX=disabled
2、关闭防火墙:
[root@PYTHON27 /]# service iptables stop[root@PYTHON27 /]# chkconfig iptables off
3、安装EPEL源:
[root@PYTHON27 /]# yum -y install epel-release[root@PYTHON27 /]# yum clean all[root@PYTHON27 /]# yum makecache
4、安装系统工具:
[root@PYTHON27 /]# yum -y install vim wget telnet
5、安装编译支持包:
[root@PYTHON27 /]# yum -y install gcc gcc-c++ automake autoconf
6、安装Nginx支持包:
[root@PYTHON27 /]# yum -y install zlib zlib-devel pcre pcre-devel openssl openssl-devel
7、安装uwsgi及组件:
[root@PYTHON27 /]# yum -y install uwsgi uwsgi-devel uwsgi-plugin-python
8、查看uwsgi版本:
[root@PYTHON27 /]# uwsgi --version2.0.14
9、启动uwsgi项目:
[root@PYTHON27 /]# uwsgi --ini /usr/local/src/python-test/python-test.ini
10、解压nginx安装包:
[root@PYTHON27 /]# tar -xzvf /usr/local/src/nginx-1.10.1.tar.gz -C /usr/local/src/
11、编译、安装:
[root@PYTHON27 /]# cd /usr/local/src/nginx-1.10.1[root@PYTHON27 nginx-1.10.1]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module[root@PYTHON27 nginx-1.10.1]# make -j 2[root@PYTHON27 nginx-1.10.1]# make install
12、修改Nginx配置文件:
[root@PYTHON27 /]# vim /usr/local/nginx/conf/nginx.conf
将下边内容: location / { root html; index index.html index.htm; } 替换为: location / { include uwsgi_params; uwsgi_read_timeout 3600; uwsgi_pass 127.0.0.1:9090; }
13、启动nginx服务:
[root@PYTHON27 /]# /usr/local/nginx/sbin/nginx -t[root@PYTHON27 /]# /usr/local/nginx/sbin/nginx
14、测试:
[root@PYTHON27 /]# curl http://192.168.75.150/Hello World
源码:
python-test.py:
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return ["Hello World"]
python-test.ini:
[uwsgi]socket = 127.0.0.1:9090wsgi-file = /usr/local/src/python-test/python-test.pyplugins = pythonchdir = /usr/local/src/python-testprocesses = 2threads = 2post-buffering = 8192buffer-size = 65535socket-timeout = 10stats = 127.0.0.1:9191# callable = python-testuid = uwsgigid = uwsgimaster = trueprotocol = uwsgibuffer-size = 8192pidfile = /var/run/uwsgi9090.pid# daemonize = /var/log/uwsgi9090.log
注释: socket = 127.0.0.1:9090 ##启动端口9090的服务,需用nginx代理,可以对外提供服务。
http-socket = 127.0.0.1:9090 ##启动端口9090的服务,可以直接对外提供服务。
python-test.py:通过WEB页面执行服务器上的脚本:
import osdef application(env, start_response): os.chdir('/usr/local/src/python-test') retcode = os.system('sh dir.sh') if retcode == 0: ret = 'success!' else: ret = 'failure!' start_response('200 OK', [('Content-Type','text/html')]) return [ret]
[END]