[uwsgi]
# 使用nginx连接时 使用
#socket=127.0.0.1:8080
# web服务器(web服务器 监听的ip:port)的地址, 即 未部署uwsgi 运行django项目(runserver), 所访问的地址前缀(127.0.0.1:8000/index)
http=127.0.0.1:8080
# Django项目 所在的绝对路径
chdir=/Users/leesam/PycharmProjects/dailyfresh
# 相对于项目目录,wsgi.py文件所在的相对路径
wsgi-file=dailyfresh/wsgi.py
# 指定(用来接收 用户请求的)工作进程数目,整个uwsgi服务的 进程数 多于 该数目
processes=4
# 指定工作进程中的线程数
threads=2
# 指定 在所有的工作进程中 有个master进程
master=True
# 保存 工作进程中的master进程 的pid,uwsgi.pid文件的位置 在项目目录下
pidfile=uwsgi.pid
# 使uwsgi后台运行,日志保存在uwsgi.log
daemonize=uwsgi.log
# 虚拟环境所在绝对路径
virtualenv=/Users/leesam/PycharmProjects/dailyfresh/venv
# 启动
# 如果不在 uwsgi.ini文件所在的目录,需要指定uwsgi.ini的路径
$ uwsgi --ini /Users/leesam/PycharmProjects/dailyfresh/uwsgi.ini
# 执行该命令后,会在项目目录下 生成uwsgi.pid uwsgi.log两个文件
# 停止
# uwsgi --stop /Users/leesam/PycharmProjects/dailyfresh/uwsgi.pid
dailyfresh/uwsgi.py
, 来对接 调度nginx
(该nginx在mac上)
修改dailyfresh/uwsgi.py
,去掉http=127.0.0.1:8080
, 加上socket=127.0.0.1:8080
server {
listen 80;
server_name localhost;
# the splash '/' below this line represents:
# 不管你是什么地址,只要配置“location /” 一律是执行该配置
location / {
# 包含uwsgi的请求参数
include uwsgi_params;
# 转交请求给uwsgi,下面的127.0.0.1:8080是uwsgi的ip:port
uwsgi_pass 127.0.0.1:8080;
}
}
$ mkdir /usr/local/var/www/static
# 在nignx中添加配置
server {
listen 80;
server_name localhost;
# the splash '/' below this line represents:
# 不管你是什么地址,只要配置“location /” 一律是执行该配置
location / {
# 包含uwsgi的请求参数
include uwsgi_params;
# 转交请求给uwsgi,下面的127.0.0.1:8080是uwsgi的ip:port
uwsgi_pass 127.0.0.1:8080;
}
location /static {
# 指定静态文件存放的路径
alias /usr/local/var/www/static/;
}
}
6 . 在Django项目settings.py文件中 添加静态目录
配置项
# 指定 DJANGO静态文件存放的路径
STATIC_ROOT = '/usr/local/var/www/static/'
修改/usr/local/var/www/static/目录的权限,使得django可以向其中 写入文件
$ chmod 777 /usr/local/var/www/static/
django收集静态文件的命令:
# 该命令会把项目中用到的静态文件 放到STATIC_ROOT指定的路径中
$ python manage.py collectstatic
重启nginx
# 重启nginx
$ nginx -s reload
用户请求-服务流程
调度nginx服务器(即mac上的nginx)
,使其 可以访问celery所在的nginx服务器。
鉴于 调度nginx服务器 和 celery所在的nginx服务器 在同一台主机上,是不是就不用配置了? server {
listen 80;
server_name localhost;
# the splash '/' below this line represents: 不管你是什么地址,只要配置“location /” 一律是执行该配置
location / {
# 包含uwsgi的请求参数
include uwsgi_params;
# 转交请求给uwsgi
uwsgi_pass 127.0.0.1:8080;
}
# 请求的地址 以/static开头,会匹配到该目录下
location /static {
# 指定静态文件存放的路径
alias /usr/local/var/www/static/;
}
# 'location = / {}' 表示只匹配'/',多点东西 或者 少点东西 都不行
location = / {
# 传递请求 给celery服务器上的 nginx,但是celery和调度nginx在同一台主机上,是不是就不用传递了?
proxy_pass http://10.211.55.2:8989;
}
}
# 添加
upstream dailyfresh {
server 127.0.0.1:8080;
server 127.0.0.1:8081;
}
server {
listen 80;
server_name localhost;
# the splash '/' below this line represents: 不管你是什么地址,只要配置“location /” >一律是执行该配置
location / {
# 包含uwsgi的请求参数
include uwsgi_params;
# 转交请求给uwsgi
#uwsgi_pass 更改为dailyfresh;
uwsgi_pass dailyfresh;
}
# 请求的地址 以/static开头,会匹配到该目录下
location /static {
# 指定静态文件存放的路径
alias /usr/local/var/www/static/;
}
# 'location = / {}' 表示只匹配'/',多点东西 或者 少点东西 都不行
location = / {
# 传递请求 给celery服务器上的 nginx,但是celery和调度nginx在同一台主机上,是>不是就不用传递了?
proxy_pass http://10.211.55.2:8989;
}
}
配置 提供静态页面的nginx
server {
listen 8989;
server_name localhost;
location /static {
alias /Users/leesam/dailyfresh/static/;
}
location / {
root /Users/leesam/dailyfresh/static/;
index index.html index.htm;
}
}
由于当初 提供静态页面的nginx
没有和 fdfs的nginx
放在一起,导致静态页面 可能获取不到图, css 和js等资源。
配置完后的访问模型图:
uwsgi+nginx 部署图
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有