how to deploy django 1.8 application with nginx and gunicorn on ubuntu 14.04 - django

Hi am developing my first web application and i have used django for the same. Now, after completing developing the site i want to host the same on a web server. I do have high speed static ip internet and dedicated server available for the same.
I want to use nginx and gunicorn for the purpose of server applications, i have thoroughly googled the topic and gone through at least 20 tutorials for deploying django applications, but almost all them have explained the process with older versions of django.
I have used django 1.8, it would be of great help if someone could provide a source to refer to continue with the deployment of the site.
Thanks in advance

The version of Django does not matter, i suggest you follow the next tutorial Deployment Django nginx supervisor

Related

How to set virtualenv to stay active on a host server

I created a website that uses vuejs as the frontend and django as the backend with another service running behind everything that im making api calls to.
So django is setup in a way to look at the dist folder of Vuejs and serve it if you run manage.py runserver. but the problem is that my service that I created is
is also in python and it needs to run in a virtualenv in order to work (It uses tensorflow 1.15.2 and this can only run in a contained environment)
I'm sitting here and wondering how I can deploy the django application and keep the virtualenv active and Im coming up with nothing, I've tried doing some research on this but everything I found was not relevant to my problem. I've deployed it and when I close the ssh connection the virtualenv stops.
If there is anyone that can enlighten my ways I would appreciate it.
i think you need to nginx: https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
if you are search for keep states just in terminal i suggest tmux https://github.com/tmux/tmux/wiki
You can use uWSGI and nginx to deploy Django apps on server. Here's helpful articles:
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
https://www.digitalocean.com/community/tutorials/how-to-set-up-uwsgi-and-nginx-to-serve-python-apps-on-centos-7
Django official docs also has a page about it: https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/uwsgi/
There are articles from developers so you can refer them in case you get stuck anywhere:
https://www.freecodecamp.org/news/django-uwsgi-nginx-postgresql-setup-on-aws-ec2-ubuntu16-04-with-python-3-6-6c58698ae9d3/
https://medium.com/#biswashirok/deploying-django-python-3-6-to-digital-ocean-with-uwsgi-nginx-ubuntu-18-04-3f8c2731ade1

Django + Docker best practice: use runserver or wsgi.py?

I've been reading a lot of blog posts (like this one) on how to deploy Django in a containerized Docker environment.
They all use the runserver command in the docker-compose.yml.
Even the Docker documentation does this.
This suprises me, since using the Django web server is not recommended for production!
What is recommended is pointing the webserver to wsgi.py.
However, none of the articles I've found on Django and Docker explain why they use runserver instead of pointing apache or nginx to wsgi.py.
Why would all these articles use the built-in Django development webserver to handle requests, instead of a full blown webserver like apache or nginx?
Isn't the point of using containers in development, to keep that environment as close to production as possible? Then why build a not-production-ready environment?
The aim of most guides including this you given is to give you a ABC guide to containerize your django applicaiton quickly with docker.
When you decided to read these guides, you are certainly ansumed as experienced django developer, but a new docker user. So the emphasis of these article will not tell you how to use production server(like uwsgi, gunicorn) to manage your django application, because it assumes your are familiar with that.
As a new docker user, it will put more effort to tell you how to dockerize them in container with a start django project. Then, a simple hello-world-like project with development django http server will be the most suitable option.
But, you still need to use uwsgi, gunicorn etc to deploy you apps, E.g. https://hub.docker.com/r/dockerfiles/django-uwsgi-nginx

Django deployment in centos server

I generally deploy django web applications in Ubuntu.
But currently we are using cpanel(not looking for alternatives) which doesnt work in Ubuntu. so want to know if moving to centos for cpanel is worth ?
Because my fear is, if we move to centos server, do we have to face some complex issues(with django deployment) that we might take lot of time(we are good at Ubuntu).
Deploying on centos is essentialy the same. You will probably want to run django in gunicorn and supervisor watching over the process. And nginx for serving static files.
I have done deployment on CentOS aswell as on Ubuntu and I didn't encounter any problems.
You can use the below link to help you in deployment
https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-centos-7
and if you had any issues in permission you can disable SE-LINUX

How could i use let's encrypt behind a django application without stopping the server?

I have a django application running on a server. I want to use let's encrypt to provide an encrypted connection. I could use the standalone option of their ACME client, but i don't want to stop my server, what i would have to do.
So there is the webroot option, that work with my allready running webserver (nginx). Django would process the request in this case. My question is, how should it look like on the django side to get this running (keeping automated renewal several months in mind)?
I don't know what setup others use, but I generally set up Django apps with Nginx serving static content and Gunicorn as the application server. It's widely accepted that Django apps usually use this kind of two web server setup. The standard instructions for setting up Let's Encrypt with Nginx worked fine for me.
Or Digital Ocean have an excellent guide too.
EDIT: It looks like Nginx can do a "graceful" reload that just updates the config with no downtime. For Debian or Ubuntu pre Systemd this would be sudo service nginx reload, while for a distro with Systemd the command is sudo systemctl reload nginx.service.
In case other users come this way like I did from Google, here's how I improved this situation:
I was unsatisfied by my options when it came to creating ACME challenges for Let's Encrypt when running a Django application. So, I rolled my own solution and created a Django app! Basically, you can manage your ACME challenges as just another object, and the app will produce the proper end-point URL.
Yes you are installing an app which means a deploy / update to your app, but once you've done that managing your challenges is far easier in the long run.
Simply pip install django-letsencrypt and follow the README to be on your way.

What is the benefit of installing gunicorn for my django app on heroku?

I have recently switched to Django for a web app I'm developing and I followed the instructions at Heroku for getting a Django app running on Heroku. I have a virtual environment in which my app is developed and I use git for version control and to push to Heroku. The link above suggests that I intall gunicorn:
The examples above used the default HTTP server for Django. For
production apps, you may wish to use a more production-ready embedded
webserver, such as Tornado, gevent’s WSGI server, or Gunicorn.
They then walk the user through installing Gunicorn.
My question is: what problems might I run into if I skip this step and just stay with the default? What benefits will Gunicorn give me?
Gunicorn is production ready and really easy to use. I use it for my websites. You usually should run it via a reverse proxy like Nginx. I'm not sure what Heroku is using. You really should try it.
In my experience it's much easier to use and configure than apache & mod_wsgi, and the other similar setups.
edit/update:
As a summary of the comments below, Heroku already uses Nginx as a reverse proxy
Much better performance, and probably better security and stability, too. Django's development web server (which is used by Heroku by default) isn't really designed to serve production applications.
django's server, is a development server . It is light weigh and easy to use but should not be used in production because it is not production ready. it cannot handle many requests. This link offers a comparison between gunicorn, uwsgi and django's development server.