uwsgi配置

uwsgi安装

安装uwsgi

pip install uwsgi

启动uwsgi

uwsgin --ini uwsgi.ini

# 后台启动
nohup uwsgi --ini uwsgi.ini &

uwsgi配置

[uwsgi]
# 是否作为主进程
master = true
# 启动uwsgi的端口号,非项目端口,
http=:8080 # 坑:这里用http可以直接用外网访问,如果要用nginx代理则需要改成socket
# 项目目录
chdir = /home/paul/tb_commodity/
# 启动文件
wsgi-file=/home/paul/tb_commodity/manage.py
# 实例Flask对象的app名如果是(all_app)则写callable=all_app
callable=app
# 进程数
processes=4
# 线程数
threads=2
buffer-size = 65536
vacuum=true
# pid存储的路径
pidfile =./uwsgi.pid
# python环境
home=/home/paul/virtual_env/tb_commodity_env/
# 启动文件名,如果是app则写app
module=manage

纯净版uwsgi配置

[uwsgi]
master = true
http=:8080
chdir = /home/paul/tb_commodity/
wsgi-file=/home/paul/tb_commodity/manage.py
callable=app
processes=4
threads=2
buffer-size = 65536
vacuum=true
pidfile =./uwsgi.pid
home=/home/paul/virtual_env/tb_commodity_env/
module=manage # 其他可以根据需要配置

nginx安装部署

nginx安装

配置EPEL源

sudo yum install -y epel-release

sudo yum -y update

安装Nginx

yum install -y nginx

启动Nginx

systemctl start nginx

停止nginx

systemctl stop nginx

重启nginx

systemctl restart nginx

查看nginx状态

systemctl status nginx

禁止开机启动nginx

systemctl disable nginx

nginx配置

# 完整的nginx.conf
user nginx
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid
include /usr/share/nginx/modules/*.conf events{ }
http{
server {
# 监听你外网访问的端口号
listen 80;
# 配置域名或者ip
server_name 121.199.68.77;
location /{
include uwsgi_params;
# 转发到那个地址,转发到uwgi的地址,在通过uwsgi来启动我们的项目
uwsgi_pass 0.0.0.0:8999;
uwsgi_connect_timeout 60;
}
}
}

需要代理一个服务,则在http中添加一个server

server {
# 监听你外网访问的端口号
listen 80;
# 配置域名或者ip
server_name 121.199.68.77;
location /{
include uwsgi_params;
# 转发到那个地址,转发到uwgi的地址,在通过uwsgi来启动我们的项目
uwsgi_pass 0.0.0.0:8999;
uwsgi_connect_timeout 60;
}
} # 根据自己的情况,更改就好

uwsgi配置中的坑

1.如果要看uwsgi启动没有,可以用用命令netstat -anp|grep 端口号来查看,这里的端口号,不是你项目中的端口号,而是你在uwsgi中配置的端口号

2.uwsgi中,如果你用的是http=:8080则可以通过外网直接来访问,但是用nginx代理会报错,我报的错误是504502,而如果要用nginx来反向代理的话需要改成socket=:8080,但是改成socket后,直接访问uwsgi访问不了。(个人碰到比较坑的地方)

3.如果是云服务器,一定不要忘记安全组要放行端口,刚开始就是直接启动服务,怎么都访问不了。能ping通ip的话,端口访问不了,就从服务器控制台-安全组,防火墙,SElinux来排查。

4.最近遇到一个坑:nginx.service start-post operation timed out. Stopping.

大概就是在启动nginx时,systemctl start nginx会夯住几分钟,这几分钟ngxin是可以访问的,但是后面就会报错,如下:

[root@iZwz9fnlmotggn5gy1wsffZ conf]# systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

根据提示查看报错:systemctl status nginx.service

systemctl status nginx.service
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2019-11-15 11:43:10 CST; 15s ago
Docs: http://nginx.org/en/docs/
Process: 4363 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=1/FAILURE)
Process: 4257 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Process: 4253 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Process: 4251 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 3183 (code=exited, status=0/SUCCESS) Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ kill[4363]: -p, --pid print pids without signaling them
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ kill[4363]: -l, --list [=<signal>] list signal names, or convert one to a name
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ kill[4363]: -L, --table list signal names and numbers
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ kill[4363]: -h, --help display this help and exit
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ kill[4363]: -V, --version output version information and exit
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ kill[4363]: For more details see kill(1).
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ systemd[1]: nginx.service: control process exited, code=exited status=1
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ systemd[1]: Failed to start nginx - high performance web server.
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ systemd[1]: Unit nginx.service entered failed state.
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ systemd[1]: nginx.service failed.

根据提示查看报错:journalctl -xe

[root@iZwz9fnlmotggn5gy1wsffZ conf]# journalctl -xe
Nov 15 11:40:59 iZwz9fnlmotggn5gy1wsffZ polkitd[2513]: Unregistered Authentication Agent for unix-process:4105:344564595 (system bus
Nov 15 11:40:59 iZwz9fnlmotggn5gy1wsffZ root[4149]: [euid=root]:root pts/2 2019-11-15 09:10 (59.33.51.12):[/usr/local/nginx/conf]2019
Nov 15 11:40:59 iZwz9fnlmotggn5gy1wsffZ root[4158]: [euid=root]:root pts/2 2019-11-15 09:10 (59.33.51.12):[/usr/local/nginx/conf]2019
Nov 15 11:41:09 iZwz9fnlmotggn5gy1wsffZ root[4176]: [euid=root]:root pts/2 2019-11-15 09:10 (59.33.51.12):[/usr/local/nginx/conf]2019
Nov 15 11:41:10 iZwz9fnlmotggn5gy1wsffZ root[4186]: [euid=root]:root pts/2 2019-11-15 09:10 (59.33.51.12):[/usr/local/nginx/conf]2019
Nov 15 11:41:13 iZwz9fnlmotggn5gy1wsffZ root[4197]: [euid=root]:root pts/2 2019-11-15 09:10 (59.33.51.12):[/bin]2019-11-15 11:41:13 r
Nov 15 11:41:14 iZwz9fnlmotggn5gy1wsffZ root[4209]: [euid=root]:root pts/2 2019-11-15 09:10 (59.33.51.12):[/bin]2019-11-15 11:41:14 r
Nov 15 11:41:40 iZwz9fnlmotggn5gy1wsffZ polkitd[2513]: Registered Authentication Agent for unix-process:4234:344570141 (system bus na
Nov 15 11:41:40 iZwz9fnlmotggn5gy1wsffZ systemd[1]: Stopped nginx - high performance web server.
-- Subject: Unit nginx.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has finished shutting down.
Nov 15 11:41:40 iZwz9fnlmotggn5gy1wsffZ systemd[1]: Starting nginx - high performance web server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has begun starting up.
Nov 15 11:41:40 iZwz9fnlmotggn5gy1wsffZ nginx[4251]: nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
Nov 15 11:41:40 iZwz9fnlmotggn5gy1wsffZ nginx[4251]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Nov 15 11:41:40 iZwz9fnlmotggn5gy1wsffZ systemd[1]: PID file /var/run/nginx.pid not readable (yet?) after start-post.
Nov 15 11:43:10 iZwz9fnlmotggn5gy1wsffZ systemd[1]: nginx.service start-post operation timed out. Stopping.

实际上是nginx服务起来后,又自动停止了。

可以看到:

nginx.service start-post operation timed out. Stopping.

PID file /var/run/nginx.pid not readable (yet?) after start-post.

解决:

1.检查nginx.conf文件,发现是nginx.conf中没有指定pid的路径

2.nginx.conf中pid需要和nginx.service配置的pid路径一致

3.找到nginx.service文件:find / -name 'nginx.service'

4.最后配置nginx.conf中的配置

5.systemctl start nginx 

6.正常启动

技术支持

centos7安装python3.6.5技术支持:https://www.cnblogs.com/oden/p/11765251.html

Nginx+uWSGI部署flask项目的更多相关文章

  1. 使用Nginx和uwsgi部署Flask项目

    前言   之前用Flask框架开发了一个Python的Web项目,使用Nginx和uWSGI部署起来感觉挺麻烦,过程中还因为对Flask框架的不熟悉,花了好长时间才把应用完全部署起来.下面分享部署成功 ...

  2. CentOS 下用 Nginx 和 uwsgi 部署 flask 项目

    前几天利用flask 写了几个调用salt-api 的接口,需要上线到正式环境,搜了一下 都是 用 nginx + uwsgi 来部署,这里记录下关键的配置项. 1.首先将代码上传到服务器上目录为: ...

  3. nginx+uwsgi部署django项目

    1.django项目部署前需要生成admin的静态资源文件 (1)生成admin的静态资源文件 # 关闭debug模型 DEBUG = False # 允许所有域名访问 ALLOWED_HOSTS = ...

  4. Nginx + uWSGI 部署Django 项目,并实现负载均衡

    一.uWSGI服务器 uWSGI是一个Web服务器,它实现了WSGI协议.uwsgi.http等协议.Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换. 要注意 WSGI ...

  5. 使用Nginx+uWSGI部署Django项目

    1.linux安装python3环境 参考链接:https://www.cnblogs.com/zzqit/p/10087680.html 2.安装uwsgi pip3 install uwsgi l ...

  6. nginx + uwsgi 部署django项目

    因项目需求,需要部署django项目,这里是基础的nginx配合uwsgi部署django,后续会采用docker部署的方式 环境: centos7 python3.5.4 django2.1.4 u ...

  7. nginx+uwsgi部署Django项目到Ubuntu服务器全过程,以及那些坑!!!

    前言:自己在windows上用PyCharm编写的Django项目,编写完后在windows上运行一点问题都没有,但是部署到服务器上时却Bug百出.百度,CSDN,sf,各种搜索寻求解决方案在历时3天 ...

  8. CENTOS7 使用 Nginx + Uwsgi 部署 Django 项目

    写在前面的话 最近总是见到有新学 Django 的朋友在部署自己的项目到 Linux 上面的时候运行不起来,所以就动手写了这篇博客. 对于不会搭建 Python 3 环境的朋友可以参考前面的博客[CE ...

  9. nginx+uwsgi部署flask应用后只能在本机访问解决办法,ipv4 和ipv6

    我的系统是centos7 nginx监听8888端口 在window下  :telnet 192.168.81.224 8888  发现连接不上, 端口22能连上 关闭224的防火墙就好了 syste ...

随机推荐

  1. ansible----sudo

    ansible 执行sudo的root命令,参看https://www.cnblogs.com/infaaf/p/10049896.html [nnn]103 ansible_ssh_host=10. ...

  2. 外网访问oracle 很慢

    一台oracle服务器  对外网开放服务,外网连接后查询速度很慢,内网查询非常快.应该是这个cisco的防火墙有问题,查了很久 没有找到原因. 临时解决方法,在内网再建一台 跳转服务器,外网查询数据库 ...

  3. table-cell设置宽高、居中

    table-cell默认宽高由内容决定 <style type="text/css" rel="stylesheet"> .content { co ...

  4. 基于 webGL 的元素周期表 3D 交互展示

    前言 之前在网上看到别人写的有关元素周期表的文章,深深的勾起了一波回忆,记忆里初中时期背的“氢氦锂铍硼,碳氮氧氟氖,钠镁铝硅磷,硫氯氩钾钙”.“养(氧)龟(硅)铝铁盖(钙),哪(钠)家(钾)没(镁)青 ...

  5. ElasticSearch集群-Windows

    概述 ES集群是一个P2类型的分布式系统,除了集群状态管理以外,其他所有的请求都可以发送到集群内任意一台节点上,这个节点可以自己找到需要转发给哪些节点,并且直接跟这些节点通信.所以,从网络架构及服务配 ...

  6. Vue中的递归组件

    递归函数我们都再熟悉不过了,也就是函数自己调用自己.递归组件也是类似的,在组件的template内部使用组件自身.那递归组件有什么使用场景呢? 我们都知道树这个数据结构就是一种递归的结构,因此我们可以 ...

  7. C# 中Trim()、TrimStart()、TrimEnd()、ToUpper()、ToLower()的用法

    Trim():删除字符串头部及尾部出现的空格,删除的过程为从外到内,直到碰到一个非空格的字符为止,所以不管前后有多少个连续的空格都会被删除掉. TrimStart():只删除字符串的头部的空格. Tr ...

  8. mysql设置编码格式--支持中文

    创建table的时候就使用utf8编码 在每次创建表的时候都在最后加上 character set = utf8就可以很好的支持中文 create table xxx ( id int auto_in ...

  9. MySQL必知必会--分 组 数 据

    数据分组 目前为止的所有计算都是在表的所有数据或匹配特定的 WHERE 子句的 数据上进行的.提示一下,下面的例子返回供应商 1003 提供的产品数目 但如果要返回每个供应商提供的产品数目怎么办?或者 ...

  10. mybatis实体为什么要提供一个无参的构造函数

    提问:Mybatis查询结果映射到实体类的时候,实体类为什么必须有一个空的构造函数? 类中如果没有构造函数,隐藏是无参构造函数,方便实体类需要通过Mybatis进行动态反射生成.如果实体类中一旦声明构 ...