标签:log django nginx path webdev your uwsgi
本例是在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 验证结果。
标签:log,django,nginx,path,webdev,your,uwsgi 来源: https://blog.csdn.net/qpeity/article/details/122152667
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。