Question

Hosting Django applicaton - Django uWSGI Nginx Server Config

Im following this tutorial to the letter but I’m having problems with the application I’m getting 502 Nginx error

http://blog.richard.do/index.php/2013/04/setting-up-nginx-django-uwsgi-a-tutorial-that-actually-works/#comment-116

could someone help? I’ve been trying to rectify this for sometime now but i can see a way of fixing it. so thought id ask here.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Yeah its within <br> <br>/var/www/example.com/src/khcards <br> <br>so full path is <br> <br>/var/www/example.com/src/khcards/wsgi.py

Is there a wsgi.py file in you Django project? It doesn’t seem to be getting imported: <br> <br><pre> <br>added /var/www/example.com/src/khcards to pythonpath. <br>ImportError: No module named khcards.wsgi <br>unable to load app 0 (mountpoint=‘’) (callable not found or import error) <br>*** no app loaded. going in full dynamic mode *** <br></pre>

@astarr sure, <br> <br>************************************************************************************ <br>/var/www/example.com/conf/nginx.conf <br>************************************************************************************ <br> <br>server { <br> listen 80; <br> server_name khcardsonline.co.uk www.khcardsonline.co.uk; <br> root /var/www/example.com/src/khcards; <br> access_log /var/www/example.com/logs/access.log; <br> error_log /var/www/example.com/logs/error.log; <br> <br> location /static/ { # STATIC_URL <br> alias /var/www/example.com/src/static/static/; # STATIC_ROOT <br> expires 30d; <br> } <br> <br> location /media/ { # MEDIA_URL <br> alias /var/www/example.com/src/media/; # MEDIA_ROOT <br> expires 30d; <br> } <br> <br> location / { <br> include uwsgi_params; <br> uwsgi_pass 127.0.0.1:8889; <br> } <br>} <br> <br> <br>************************************************************************************ <br>/var/www/example.com/conf/uwsgi.ini <br>************************************************************************************ <br> <br>[uwsgi] <br># variables <br>projectdomain = khcardsonline.co.uk www.khcardsonline.co.uk <br> <br>uid = www-data <br>god = www-data <br>chmod = 775 <br> <br># config <br>plugins = python <br>master = true <br>pidfile=/tmp/project-master.pid <br>protocol = uwsgi <br>env = DJANGO_SETTINGS_MODULE=khcards.settings <br>pythonpath = /var/www/example.com/src/khcards <br>module = khcards.wsgi:application <br>socket = 127.0.0.1:8889 <br>logto = /var/www/example.com/src/logs/uwsgi.log <br>#below line runs it as a daemon in background <br>daemonize = /var/log/uwsgi/khcards.log <br> <br>************************************************************************************ <br>/var/www/example.com/logs/uwsgi.log <br>************************************************************************************ <br> <br>*** Starting uWSGI 1.0.3-debian (64bit) on [Wed Apr 16 08:57:08 2014] *** <br>compiled with version: 4.6.3 on 17 July 2012 02:26:54 <br>current working directory: /var/www/example.com <br>detected binary path: /usr/bin/uwsgi-core <br>uWSGI running as root, you can use --uid/–gid/–chroot options <br>*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** <br>your memory page size is 4096 bytes <br>uwsgi socket 0 inherited INET address 127.0.0.1:8889 fd 4 <br>Python version: 2.7.3 (default, Feb 27 2014, 20:09:21) [GCC 4.6.3] <br>Python main interpreter initialized at 0x2457ed0 <br>your server socket listen backlog is limited to 100 connections <br>*** Operational MODE: single process *** <br>added /var/www/example.com/src/khcards/ to pythonpath. <br>ImportError: No module named khcards.wsgi <br>unable to load app 0 (mountpoint=‘’) (callable not found or import error) <br>*** no app loaded. going in full dynamic mode *** <br>*** uWSGI is running in multiple interpreter mode *** <br>gracefully (RE)spawned uWSGI master process (pid: 12881) <br>spawned uWSGI worker 1 (pid: 14856, cores: 1) <br> <br> <br>************************************************************************************ <br>/var/www/example.com/logs/error.log sample <br>************************************************************************************ <br>2014/04/16 08:59:00 [error] 787#0: 1 connect() failed (111: Connection refused) while connecting to upstream, client: 200.29.238.180, server: khcardsonline.co.uk, request: “HEAD / HTTP/1.0”, upstream: “uwsgi://127.0.0.1:8889” <br> <br>*********************************************************************************** <br>/var/log/uwsgi/logs/example_project.log <br>************************************************************************************ <br> <br>*** Starting uWSGI 1.0.3-debian (64bit) on [Wed Apr 16 08:32:32 2014] *** <br>compiled with version: 4.6.3 on 17 July 2012 02:26:54 <br>current working directory: /var/www/example.com <br>detected binary path: /usr/bin/uwsgi-core <br>uWSGI running as root, you can use --uid/–gid/–chroot options <br>*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** <br>your memory page size is 4096 bytes <br>uwsgi socket 0 bound to TCP address 127.0.0.1:8889 fd 4 <br>Python version: 2.7.3 (default, Feb 27 2014, 20:09:21) [GCC 4.6.3] <br>Python main interpreter initialized at 0x1286f10 <br>your server socket listen backlog is limited to 100 connections <br>*** Operational MODE: single process *** <br>added /var/www/example.com/src/khcards to pythonpath. <br>ImportError: No module named khcards.wsgi <br>unable to load app 0 (mountpoint=‘’) (callable not found or import error) <br>*** no app loaded. going in full dynamic mode *** <br>*** uWSGI is running in multiple interpreter mode *** <br>spawned uWSGI master process (pid: 12881) <br>spawned uWSGI worker 1 (pid: 12882, cores: 1) <br>[pid: 12882|app: -1|req: -1/1] 81.111.153.236 () {36 vars in 584 bytes} [Wed Apr 16 08:32:47 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/2] 81.111.153.236 () {38 vars in 585 bytes} [Wed Apr 16 08:32:47 2014] GET /favicon.ico => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/3] 81.111.153.236 () {36 vars in 569 bytes} [Wed Apr 16 08:32:49 2014] GET /apple-touch-icon-precomposed.png => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/4] 81.111.153.236 () {36 vars in 545 bytes} [Wed Apr 16 08:32:49 2014] GET /apple-touch-icon.png => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/5] 81.111.153.236 () {36 vars in 584 bytes} [Wed Apr 16 08:33:12 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/6] 81.111.153.236 () {38 vars in 585 bytes} [Wed Apr 16 08:33:12 2014] GET /favicon.ico => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/7] 81.111.153.236 () {36 vars in 569 bytes} [Wed Apr 16 08:33:14 2014] GET /apple-touch-icon-precomposed.png => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/8] 81.111.153.236 () {36 vars in 545 bytes} [Wed Apr 16 08:33:14 2014] GET /apple-touch-icon.png => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/9] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:37:39 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/10] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:42:02 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/11] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:42:03 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/12] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:42:04 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/13] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:42:04 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/14] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:42:04 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/15] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:42:05 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/16] 115.239.248.112 () {34 vars in 486 bytes} [Wed Apr 16 08:43:25 2014] GET /manager/html => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/17] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:11 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/18] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:13 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/19] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:13 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/20] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:13 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/21] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:14 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/22] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:14 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/23] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:14 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/24] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:14 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/25] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:14 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/26] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:15 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/27] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:50:15 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/28] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:51:40 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/29] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:51:42 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/30] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:51:44 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/31] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:51:44 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/32] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:51:44 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/33] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:40 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/34] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:41 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/35] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:42 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/36] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:42 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/37] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:42 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/38] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:42 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/39] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:42 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/40] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:43 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/41] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:43 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/42] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:43 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/43] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:43 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/44] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:43 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/45] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:43 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/46] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:44 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>[pid: 12882|app: -1|req: -1/47] 81.111.153.236 () {38 vars in 651 bytes} [Wed Apr 16 08:56:44 2014] GET / => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0) <br>…brutally killing workers… <br>binary reloading uWSGI… <br>chdir() to /var/www/example.com <br>closing all non-uwsgi socket fds > 2 (_SC_OPEN_MAX = 1024)… <br>found fd 4 mapped to socket 0 (127.0.0.1:8889) <br>running /usr/bin/uwsgi-core <br>[uWSGI] getting INI configuration from /var/www/example.com/conf/uwsgi.ini <br> <br>Let me know if you would like anything else <br>