Hosting the django app in an nginx server - django

I have developed a django app and I want to deploy it now. My friend has a site on his own, which is an nginx server. I want to host my app as a subdomain in his site. Now I am clueless of what to do now. Hours of browsing did not help me. What is that I have to do to host my app?

The easiest Django deployment with nginx server is via gunicorn. You can follow tutorial in How to deploy Django Project using NGINX and gunicorn.
Notice that server condition may differ one from another. So, trial and error is commom workaround. Have a nice try! (I usually deploy my Django projects on nginx + gunicorn too ;-).
Domain or subdomain doesn't matter. But the subdirectory matters.

Related

React and Django deployment

I developed an app and I want to deploy it on a server. For backend I use Django and for frontend React. The communication between React and Django is via rest api. I also have an Arduino which communicates with Django via rest. I use nginx on server. What is the best way how to deploy this app? Thanks a lot
Well you need a server, popular choices to rent one are AWS or Heroku. Both have a free limited trial and tutorials that explain to you how to deploy your project. Heroku should be a easier to use, while AWS provides more features. Links:
-AWS Elastic Beanstalk: https://aws.amazon.com/it/elasticbeanstalk/
-Heroku: https://www.heroku.com
There are lots of available alternatives of build and orchestration tools.
For example Ansible has many modules for django, nginx, npm, databases... that allow to perform any actions and commands whatever you want. Just configure some webhooks in your repository settings so you could trigger autodeploy by pushing new changes or run it manually if needed.
What i did was use my VPS to host the Django app, and then used graphql (similar to REST) to communicate from React to Django.
The general steps are:
1) on the VPS server, you will have a code directory w/ your Django app, like on your local machine. Just use git to get it there.
2) create a virtualenv on the VPS server with all your needed django/python modules (added via pip) in your code directory
3) create an nginx conf file. i use nginx to proxy_pass to apache, which calls the python app. my nginx listens on port 80, and has a line this this: proxy_pass http://admin.mysite.com:81;. Create a link to this config in /etc/nginx/sites-enabled/ and restart nginx.
4) create an apache conf file with <VirtualHost *:81> with key lines such as: WSGIDaemonProcess and WSGIScriptAlias which point to your virtual env and your wsgi.py file. make sure to enable this too ('a2ensite`).
5) your project's wsgi.py file will point to your app's settings.
6) restart apache and nginx.
That's the real rough outline, and there are tutorials written. Just search for 'django uwsgi nginx' and that will get your django app running, with the proper endpoints for your react app to call.
you can use 1 server with nginx and gunicorn and make the axios to point to localhost for the react app, create 1 gunicorn for the django and 2 nginx 1 for the django and the other for the react,
Gunicorn use the socket and service file you can use the below link (it will help you for the deployment of django):
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-18-04
for the react app it is easier, you can make the build on your local and clone the project on the server (make the app to point to localhost)
just create nginx file with the belw:
server {
server_name yourdomain.com;
root /project-path/;
index index.html index.htm;
location / {
try_files $uri /index.html =404;
}
}

Strategic error on Python/Flask deploy

I'm new to web development and deployment however I developed a web site using Python 2.7 and Flask. I can't get the site to load when the user hits the site. When testing on the server using SSH the program starts like it did on my development PC but does not render the first template and shows this error: WARNING: Do not use the development server in a production environment. Use a production WSGI server instead.
In researching that error I found an article that says Flask is not meant for a multi-user public web environment. Further investigation said: If you want to run Flask in production, be sure to use a production-ready web server like Nginx, and let your app be handled by a WSGI application server like Gunicorn.
I think what this is telling me is:
Find a provider that supports Nginx.
Install Gunicorn and then configure it to run on that host.
Doing that should allow my program to run on the host server and be accessible to the world.
Would folks with experience with Python/Flask web apps please confirm the direction I should be heading as I can't afford to go down the wrong path again.

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

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

How to deploy django site on Windows server with Nginx?

Maybe anybody know easy and work solution for deploying django site on Windows machine with Nginx reverse proxy server? I can't find WSGI module, that have support in Windows.

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.