uWSGI+Nginx安装、配置

1、关闭SELINUX:

1
[root@PYTHON27 /] # vim /etc/selinux/config
1
将SELINUX=enforcing修改为SELINUX=disabled

2、关闭防火墙:

1
2
[root@PYTHON27 /] # service iptables stop
[root@PYTHON27 /] # chkconfig iptables off

3、安装EPEL源:

1
2
3
[root@PYTHON27 /] # yum -y install epel-release
[root@PYTHON27 /] # yum clean all
[root@PYTHON27 /] # yum makecache

4、安装系统工具:

1
[root@PYTHON27 /] # yum -y install vim wget telnet

5、安装编译支持包:

1
[root@PYTHON27 /] # yum -y install gcc gcc-c++ automake autoconf

6、安装Nginx支持包:

1
[root@PYTHON27 /] # yum -y install zlib zlib-devel pcre pcre-devel openssl openssl-devel

7、安装uwsgi及组件:

1
[root@PYTHON27 /] # yum -y install python-devel uwsgi uwsgi-devel uwsgi-plugin-python

8、查看uwsgi版本:

1
2
[root@PYTHON27 /] # uwsgi --version
2.0.14

9、启动uwsgi项目:

1
[root@PYTHON27 /] # uwsgi --ini /usr/local/src/python-test/python-test.ini

10、解压nginx安装包:

1
[root@PYTHON27 /] # tar -xzvf /usr/local/src/nginx-1.10.1.tar.gz -C /usr/local/src/

11、编译、安装:

1
2
3
4
[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配置文件:

1
[root@PYTHON27 /] # vim /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
将下边内容:
         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服务:

1
2
[root@PYTHON27 /] # /usr/local/nginx/sbin/nginx -t
[root@PYTHON27 /] # /usr/local/nginx/sbin/nginx

14、测试:

1
2
[root@PYTHON27 /] # curl http://192.168.75.150/
Hello World

 

源码:

python-test.py:

1
2
3
def application( env , start_response):
     start_response( '200 OK' , [( 'Content-Type' , 'text/html' )])
     return  [ "Hello World" ]

python-test.ini:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[uwsgi]
socket = 127.0.0.1:9090
wsgi- file  /usr/local/src/python-test/python-test .py
plugins = python
chdir =  /usr/local/src/python-test
processes = 2
threads = 2
post-buffering = 8192
buffer-size = 65535
socket-timeout = 10
stats = 127.0.0.1:9191
# callable = python-test
uid = uwsgi
gid = uwsgi
master =  true
protocol = uwsgi
buffer-size = 8192
pidfile =  /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页面执行服务器上的脚本:

1
2
3
4
5
6
7
8
9
10
11
import  os
 
def 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]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值