qpython3安装requirements_pip3安装uwsgi|python3安装|nginx|uwsgi|flask

本文详细介绍了在CentOS7.3系统上,如何使用yum安装Python3、pip3、Nginx和MySQL,并通过pip3安装uwsgi。接着,展示了如何编写Python3的Flask应用并测试uwsgi,创建uwsgi配置文件,以及设置uwsgi为系统服务以便开机启动。最后,提到了Nginx的配置文件示例,用于反向代理uwsgi服务,确保网站可以通过80端口访问。
摘要由CSDN通过智能技术生成

pip3安装uwsgi|python3安装

环境/软件版本:centos 7.3,yum安装nginx,yum安装mysql,yum安装python3.4

安装pip3

yum install python34-pip

pip3 安装依赖

pip3 install -r requirements

安装python34devel

yum install python34-devel

安装uwsgi

pip3 install uwsgi

编写test.py测试uwsgi,注意python3和python2的测试方法是不一样的。

defapplication(env, start_response):

start_response('200 OK', [('Content-Type','text/html')])return [b"Hello World"] #python3

#return ["Hello World"] # python2

启动uwsgi 并访问

测试uwsgi启动项目,项目启动run.py文件代码,

#!usr/bin/python#-*- coding: utf-8 -*-

from app importappif __name__ == "__main__":

app.run()

测试http启动命令,访问端口5000,能够正常访问网站,到此,python3,pip3,flask项目代码,uwsgi,全部测试成功

uwsgi --socket 0.0.0.0:5000 --protocol=http -w run:app

编写uwsgi.ini,以wsgi方式启动uwsgi,此时无法通过web访问的方式测试是否启动,

查看控制台提示即可

uwsgi.ini-uwsgi启动的配置文件

#uwsgi配置文件[uwsgi]socket= 127.0.0.1:5000#socket=/tmp/flask.sock

chmod-socket= 660vacuum=true

chdir=/home/dc

module=run:app

wsgi-file=run.py

callable= app

uwsgi启动的linux shell命令,项目在/home/dc下

uwsgi --ini /home/dc/uwsgi.ini

如控制台出现以下提示,八成是成功了

WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x12b9fa0 pid: 2402(default app)

mountpoint already configured. skip.

uWSGI running as root, you can use--uid/--gid/--chrootoptions*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***

*** uWSGI is running in multiple interpreter mode ***spawned uWSGI worker1 (and the only) (pid: 2402, cores: 1)

接下来将uwsgi启动shell命令写成系统服务,以便开机启动

在 /usr/lib/systemd/system/   下新建uwsgi.service

我的内容如下,自测成功。

注意,使用绝对路径调用uwsgi

[Unit]

Description=uwsgi project

[Service]

Type=simple

PIDFile=/home/uwsgi.pid

ExecStart=/usr/bin/uwsgi --ini /home/dc/uwsgi.ini

ExecReload=/usr/bin/uwsgi --ini /home/dc/uwsgi.ini

ExecStop=PrivateTmp=true[Install]

WantedBy=multi-user.target

启动uwsgi服务,设置开机启动

systemctl start uwsgi

systemctl enable uwsgi

此时,除nginx以外的所有配置全部完成

nginx的配置

在/etc/nginx/conf.d下新建一个uwsgi.conf

# mysite_nginx.conf

# configuration of the server

server {

# the port your site will be served on

listen80;# the domain name it will serve for

server_name dc.blfly.com;# substitute your machine's IP address or FQDN

charset utf-8;# max upload size

client_max_body_size 75M;# adjust to taste

# Django media

# location /media {

# alias /path/to/your/mysite/media;# end as required

#}

location /static {

alias /home/dc/app/static;# your Django project's static files - amend as required

}

# Finally,send all non-media requests to the Django server.

location / {

uwsgi_pass localhost:5000;#此处与uwsgi.ini的socket是对应的

#include /path/to/your/mysite/uwsgi_params;# the ued

include uwsgi_params;#uwsgi_param UWSGI_CHDIR /home/dc;#//项目根目录

#uwsgi_param UWSGI_SCRIPT run:app;

}

}

重启nginx,访问80端口,测试网站成功访问

有什么问题,可以在下面留言问我

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值