读django文档——nginx + uwsgi 部署django项目
2021/12/27 7:13:09
本文主要是介绍读django文档——nginx + uwsgi 部署django项目,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本例是在anaconda虚拟环境webenv下面建立的django项目,名字叫webdev。
激活虚拟环境,在该环境里面安装uwsgi。
conda activate webenv conda install uwsgi
在django项目webdev目录里创建 uwsgi.ini文件,编辑内容如下。如果遇到目录不存在,比如/var/log/uwsgi,那么自行创建一下。
[uwsgi] # /path/to/your/project (full path) chdir = /data/webdev # Django's wsgi file (locate in project.wsgi.py) module = webdev.wsgi:application # the virtualenv (full path) home = /anaconda3/envs/webenv # set an environment variable env = DJANGO_SETTINGS_MODULE=webdev.settings # process-related settings # the socket (IP:port or /path/to/your/project/mysite.sock) socket = 127.0.0.1:8001 # master master=True # max number of worker processes processes = 10 # vacuum means clear environment on exit vacuum=True # respawn processes taking more than 20 seconds harakiri = 20 # respawn processes after serving 5000 requests max-requests = 5000 # background the process & log daemonize = /var/log/uwsgi/webdev.log # /path/to/pid.file (full path) #pidfile = /tmp/webdev.pid
然后初始化。
uwsgi --ini uwsgi.ini
编辑nginx配置文件 /etc/nginx/conf.d/webdev.conf,内容如下。注意里面的 static 、 media 等配置,涉及到django的 STATIC_ROOT目录。
# the upstream component nginx needs to connect to upstream webdev { # server unix:///path/to/your/mysite/mysite.sock; # for a file socket server 127.0.0.1:8001; # for a web port socket (we'll use this first) } # configuration of the server server { # the port your site will be served on listen 8000; # the domain name it will serve for server_name 192.168.27.7 # substitute your machine's IP address or FQDN charset utf-8; access_log /var/log/nginx/access.log; # max upload size client_max_body_size 75M; # adjust to taste # Django media location /media { alias /data/webdev/media; # your Django project's media files - amend as required } # Django static location /static { alias /data/webdev/static; # your Django project's static files - amend as required } # Finally, send all non-media requests to the Django server. location / { include uwsgi_params; # the uwsgi_params file you installed uwsgi_pass webdev; uwsgi_connect_timeout 20; } }
然后重启nginx,访问 IP:8000 验证结果。
这篇关于读django文档——nginx + uwsgi 部署django项目的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-29Nginx发布学习:从入门到实践的简单教程
- 2024-10-28Nginx发布:新手入门教程
- 2024-10-21nginx 怎么设置文件上传最大20M限制-icode9专业技术文章分享
- 2024-10-17关闭 nginx的命令是什么?-icode9专业技术文章分享
- 2024-09-17Nginx实用篇:实现负载均衡、限流与动静分离
- 2024-08-21宝塔nginx新增8022端口方法步骤-icode9专业技术文章分享
- 2024-08-21nginx配置,让ws升级为wss访问的方法步骤-icode9专业技术文章分享
- 2024-08-15nginx ws代理配置方法步骤-icode9专业技术文章分享
- 2024-08-14nginx 让访问带有/relid的地址返回404 ,例子 /relid-x-0.36-y-131.html-icode9专业技术文章分享
- 2024-08-14nginx 判断地址有/statics/的路径,指向到/home/html/statics/目录-icode9专业技术文章分享