user3887070
user3887070

Reputation: 45

Deploy django App on nginx with uwsgi or gunicorn not working

I am trying to deploy a django application on ubuntu with nginx server. I try to use both methods by gunicorn and uwsgi but still not workong. I go through a lot of tutorial. Main issue may be that my django app is not on virtual env. It is directly on my server. Please help me in figuring out.

Django app is working stand alone on 8000 port. and ngnix is also running. Gunicorn and uwsgi is also installed properly. uwsgi gives this error while running:

uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.10 (64bit) on [Thu Apr 16 04:49:44 2015] ***
compiled with version: 4.8.2 on 14 April 2015 02:24:25
os: Linux-3.13.0-43-generic #72-Ubuntu SMP Mon Dec 8 19:35:06 UTC 2014
nodename: movieran
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /root/mymovie
detected binary path: /usr/local/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
chdir() to /root/mymovie
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7782
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8000 fd 4
spawned uWSGI http 1 (pid: 29087)
uwsgi socket 0 bound to TCP address 127.0.0.1:52804 (port auto-assigned)     fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41)  [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xa69d20
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72768 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /var/www to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xa69d20 pid: 29086 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 29086, cores: 1)
No handlers could be found for logger "django.request"
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 189, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 218, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 261, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 97, in technical_500_response
html = reporter.get_traceback_html()
File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 384, in get_traceback_html
return t.render(c)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 209, in render
return self._render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 201, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 903, in render
bit = self.render_node(node, context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 79, in render_node
return node.render(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/debug.py", line 89, in render
output = self.filter_expression.resolve(context)
File "/usr/local/lib/python2.7/dist-packages/django/template/base.py", line 674, in resolve
new_obj = func(obj, *arg_vals)
File "/usr/local/lib/python2.7/dist-packages/django/template/defaultfilters.py", line 774, in date
return format(value, arg)
File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 345, in format
return df.format(format_string)
File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 37, in format
pieces.append(force_text(getattr(self, piece)()))
File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 270, in r
return self.format('D, j M Y H:i:s O')
File "/usr/local/lib/python2.7/dist-packages/django/utils/dateformat.py", line 37, in format
pieces.append(force_text(getattr(self, piece)()))
File "/usr/local/lib/python2.7/dist-packages/django/utils/encoding.py", line 92, in force_text
s = six.text_type(s)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 141, in __text_cast
return func(*self.__args, **self.__kw)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/__init__.py", line 84, in ugettext
return _trans.ugettext(message)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 323, in ugettext
return do_translate(message, 'ugettext')
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 300, in do_translate
_default = _default or translation(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 206, in translation
_translations[language] = DjangoTranslation(language)
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 116, in __init__
self._add_installed_apps_translations()
File "/usr/local/lib/python2.7/dist-packages/django/utils/translation/trans_real.py", line 164, in _add_installed_apps_translations
"The translation infrastructure cannot be initialized before the "django.core.exceptions.AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.
[pid: 29086|app: 0|req: 1/1] 24.90.108.186 () {38 vars in 595 bytes} [Thu Apr 16 03:50:31 2015] GET / => generated 0 bytes in 163 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)

Nginx is giving 404 error. Please help me in deployment.

I also follow this question from [1]: Django app deployment on nGINX

Upvotes: 0

Views: 1217

Answers (3)

Yazan M. Al-Horani
Yazan M. Al-Horani

Reputation: 127

I think this project can help you alot. it deploys to EC2 but you can read the source code to help you with your deployment. Its easy and does everything you ask for.

Upvotes: -1

mpcabd
mpcabd

Reputation: 1807

Well also the error might be very clearly stated at the end of the error log

Check that you don't make non-lazy gettext calls at import time

If you have translation calls in your code make sure they are lazy calls, lazy calls are not evaluated until they're needed, and that's usually on the front end or when writing the values to some output or a log. In some rare cases you will have to use non-lazy calls, but make sure they're not being executed before all the apps are ready and Django is ready, so especially in your settings.py file.

Also I second @dizballanze, DO NOT RUN uWSGI AS ROOT.

Upvotes: 1

dizballanze
dizballanze

Reputation: 1267

I think the problem is described in following line of uwsgi output:

!!! no internal routing support, rebuild with pcre support !!!

Try to install pcre:

sudo apt-get install libpcre3 libpcre3-dev

and when reinstall uwsgi:

pip uninstall uwsgi
pip install uwsgi

P.S. You are really should not run the application as root user.

Upvotes: 0

Related Questions