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 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]



posted @   Lambeto  阅读(10939)  评论(0编辑  收藏  举报
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· .NET 原生驾驭 AI 新基建实战系列(一):向量数据库的应用与畅想
· Browser-use 详细介绍&使用文档
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞
历史上的今天:
2016-02-15 VsFtpd服务配置简明笔记
2016-02-15 VsFtpd配置文件详解
点击右上角即可分享
微信分享提示