在项目目录下创建uwsgiconfig.ini文件
[uwsgi]
home=/home/ # 指定python虚拟环境,意义:使用指定的python,路径写到bin目录上一层
chdir=/home/test/project # 项目目录,意义: 将路径切换到项目目录下
wsgi-file=manager.py # 项目路径下,指定加载的启动文件
module=manager 或 manager:app # 项目路径下,指定加载的模块,同wsgi-file(若“:app”写在module中,则callable不需要再写)
callable=app # 指定uWSGI加载的启动文件(模块)中哪个变量将被调用
master=true # 启动主线程
processes=4 # 设置工作进程的数量
threads=2 # 设置每个工作进程的线程数
socket=127.0.0.1:8888 # 指定socket地址 配合nginx使用
vacuum=true # 当服务器退出时自动删除unix socket文件和pid文件
logfile-chmod=644 # 指定日志文件的权限
daemonize=%(chdir)/cloudmonitor.log # 进程在后台运行,并将日志打印到指定文件
pidfile=%(chdir)/cloudmonitor.pid # 在失去权限前,将主进程pid写到指定的文件
uid=git # uWSGI服务器运行时的用户id
gid=git # uWSGI服务器运行时的用户组id
procname-prefix-spaced=cloudmonitor # 指定工作进程名称的前缀
uwsgi uwsgiconfig.ini
uwsgi --ini uwsgiconfig.ini 启动uwsgi服务
uwsgi uwsgiconfig.ini --daemonize //后台运行启动
uwsgi --stop uwsgi.pid //停止服务
uwsgi --reload uwsgi.pid //可以无缝重启服务
nginx
在/etc/nginx/nginx.conf文件中 http 下添加 include /etc/nginx/conf.d/test.conf 其中‘test’为自己取的应用配置名
在/etc/nginx/conf.d/下,创建名为 test.conf 文件,写入一下内容:
server {
# 监听端口
listen 80;
# 监听ip 换成服务器公网IP
server_name localhost;
charset utf-8;
client_max_body_size 75M;
#动态请求
location / {
include uwsgi_params;
# 与uwsgi socket对应
uwsgi_pass 127.0.0.1:8888;
}
}
-
nginx //启动
-
nginx -s stop/quit //停止
-
nginx -s reload //重启加载配置