nginx+uwsgi部署Django遇到了麻烦
问题描述
首先说明:电脑环境为Ubuntu 16.10,我使用conda管理开发环境 !!!
uwsgi使用conda install的pip安装
uwsgi ini文件
# backend_uwsgi.ini file[uwsgi]# Django-related settings# the base directory (full path)chdir = /home/yangtz/developproject/backend# Django’s wsgi file# wsgi-file = /home/yangtz/developproject/backend/backend/wsgi.pymodule = backend.wsgi # process-related settings# mastermaster = true# maximum number of worker processesprocesses = 10# the socket (use the full path to be safesocket = /home/yangtz/developproject/backend/backend/backend.sock# ... with appropriate permissions - may be neededchmod-socket = 666# clear environment on exitvacuum = true# daemonize = /home/yangtz/developproject/backend/uwsgi.log
backend_nginx.conf
# the upstream component nginx needs to connect to upstream django {server unix:/home/yangtz/developproject/backend/backend/backend.sock; # for a file socket# server 127.0.0.1:8000; # for a web port socket (we’ll use this first) } # configuration of the server server {# the port your site will be served onlisten 80;# the domain name it will serve forserver_name 127.0.0.1; # substitute your machine’s IP address or FQDNcharset utf-8; access_log /home/yangtz/developproject/nginx_access.log;error_log /home/yangtz/developproject/nginx_error.log; # max upload sizeclient_max_body_size 75M; # adjust to taste # Django media# location /media {# alias /path/to/your/mysite/media; # your Django project’s media files - amend as required# } location /static { alias /home/yangtz/developproject/backend/static; # your Django project’s static files - amend as required} # Finally, send all non-media requests to the Django server.location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed} }
当启动 sudo uwsgi --ini backend_uwsgi.ini 后,结果却是
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** chdir() to /home/yangtz/developproject/backendyour processes number limit is 63466your memory page size is 4096 bytesdetected max file descriptor number: 1024lock engine: pthread robust mutexesthunder lock: disabled (you can enable it with --thunder-lock)uwsgi socket 0 bound to UNIX address /home/yangtz/developproject/backend/backend/backend.sock fd 3your server socket listen backlog is limited to 100 connectionsyour mercy for graceful operations on workers is 60 secondsmapped 800448 bytes (781 KB) for 10 cores*** Operational MODE: preforking ****** no app loaded. going in full dynamic mode ****** uWSGI is running in multiple interpreter mode ***!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!no request plugin is loaded, you will not be able to manage requests.you may need to install the package for your language of choice, or simply load it with --plugin.!!!!!!!!!!! END OF WARNING !!!!!!!!!!spawned uWSGI master process (pid: 9293)spawned uWSGI worker 1 (pid: 9294, cores: 1)spawned uWSGI worker 2 (pid: 9295, cores: 1)spawned uWSGI worker 3 (pid: 9296, cores: 1)spawned uWSGI worker 4 (pid: 9297, cores: 1)spawned uWSGI worker 5 (pid: 9298, cores: 1)spawned uWSGI worker 6 (pid: 9299, cores: 1)spawned uWSGI worker 7 (pid: 9300, cores: 1)spawned uWSGI worker 8 (pid: 9301, cores: 1)spawned uWSGI worker 9 (pid: 9302, cores: 1)spawned uWSGI worker 10 (pid: 9303, cores: 1)
nginx界面是
我看到 其中 !!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!no request plugin is loaded, you will not be able to manage requests.you may need to install the package for your language of choice, or simply load it with --plugin.
于是加上 --plugin python3,得到结果却是
Traceback (most recent call last): File './backend/wsgi.py', line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named ’django’unable to load app 0 (mountpoint=’’) (callable not found or import error) no app loaded. going in full dynamic mode uWSGI is running in multiple interpreter mode
nginx界面变成
nginx刷新,uswgi那里有反应。
怎么办?求助大神解救。。。
问题解答
回答1:sudo uwsgi
你切换了环境。你的 Django 不是安装在系统全局的。
如果你使用了 virtualenv 的话,你可以在 uwsgi 的配置中指定 virtualenv 的位置。
相关文章:
1. 用Java写发送邮件的程序,经常被当做垃圾邮件处理怎么解决2. docker-remote-api - docker 有哪些Web管理UI3. java - Spring boot启动时报错?4. Java Servlet中的PostgreSQL连接,用于从数据库检索信息。遇到错误5. php - java程序员必须要学GUI这块吗?6. java - tomcat部署jave-web,网页访问html中文乱码。7. javascript - nodejs 如何同步执行某些模块函数?8. java - @Component重新给bean命名后,为什么@Resource找不到?9. java - 当在子类中声明一个父类中存在的变量后,自动调用的父类构造函数不起作用。10. java中可以通过类的class属性得到该类的字节码文件对象?