We have web application which is running with django, python and PostgreSQL. We are also using virtualenv.
To start the web service, we first activate the virtualenv and then start python as service on 8080 with nohup.
But after sometime nohup process dies. Is there any way to launch service as demon like apache, or use some thing like monit?
I am new to this, please excuse my mistakes
So a runserver command should only be used in testing environments. And just like #Alasdair said, Django docs already have interesting information about that topic.
I would suggest using gunicorn as a wsgi with nginx as a reverse proxy. You can find more information here
And i would suggest using supervisor to monitor and control your gunicorn workers. More information can be found here
It may be a good idea to deploy your application using apache or ngnix. There is official Django documentation on how to do it with apache - https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/
Apache does support virtual environment - just add python-home=<path_to_your_virtual_env> to the WSGIDaemonProcess directive when using daemon mode of mod_wsgi:
WSGIDaemonProcess django python-path=/opt/portal/src/ python-home=/opt/venv/django home=/opt/portal/
Best practice for how to use mod_wsgi and virtual environments is explained in:
http://modwsgi.readthedocs.io/en/develop/user-guides/virtual-environments.html
I was able to do it, but forgot to update the answers.IF any one is looking for same they can follow this.
Best way to run django app in production is to run with
django+gunicorn+supervisor+nginx.
I used gunicorn which is a Python WSGI HTTP Server for UNIX where you can control thread count, timeout settings and much more. gunicorn was running was on socket, it could be run on port but to reduce tcp overhead we ran on socket.
Supervisor is used to run this gunicorn script as supervisor is simple tool which is used to control your process.
and with the help of nginx reverse proxy Our Django site was life.
For more details follow below blog.
http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
Related
I want to run a python script whenever there is a request to nginx. Is there any way I could run python through my nginx conf or If I could add my python script in nginx configuration?
NGINX has support for JavaScript and LUA via modules.
JavaScript in NGINX
OpenResty LUA
You could use for example the framework Flask and using WSGI within NGINX to front the python application.
Python Flask
You don't really describe your use-case enough to provide a more specific answer than this.
I want to host my Django 1.10 web application on WHM(VPS). for that i have installed Django and another necessary tools on WHM(VPS) by ssh login. and i also have uploaded my Django application code through cpanel in public_html directory.
When i run python manage.py runserver <ip_address:8000> from ssh terminal, i am able to access that application. but when i close the ssh terminal, it terminates all the running process. so could not access application after that.
So, Is there any way that without running python manage.py script i can access Django application?
Any help would be highly appreciated.
Thank you.
Django comes with a built-in development server, it's not really meant to be used when deploying to a remote VPS.
There are some great resources to help you along, but what you're likely going to want to do is deploy your app on a stack using gunicorn or uwsgi as an application server and a web server like Nginx or apache 2 as a reverse proxy.
I personally use Nginx and uwsgi.
There are some great resources explaining how to deploy a Django server. Have a look at this one from digital ocean, it was a great help when I needed to set up a production server correctly: https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-16-04
best of luck with it!
I am setting up a new project that is going to use python to build a RESTful back end. I looked at GAE, but choose Falcon Framework, because the application needs to eventually be installed on local servers. GAE has a great development feature, it allows for iterative development by watching the source, and reloading.
You can leave the web server running while you develop your
application. The web server knows to watch for changes in your source
files and reload them if necessary.
How can I set up Falcon to do the same thing?
This may not be the best answer, but I found that there is no simple method that does not require more software installed the way GAE does it, but after you install gunicorn, your can use the --reload switch and the server will auto-reload the source.
$ gunicorn -b 127.0.0.1:8000 -b [::1]:8000 --reload myapp:app
Docs: http://docs.gunicorn.org/en/19.0/settings.html#reload
Auto-reloading is not a feature of the framework (Falcon), but rather of the server. If you do want auto-reloading, the simplest way to do it is run your Falcon code on a gunicorn server, using the --reload switch. For example:
$ gunicorn --reload app:app
Assuming your API is inside app.py and named app.
Do i need to use NginX or am i able to host it without it?
I am developing my first django project and am at the point where i can run the app project using the command:
./manage.py run_gunicorn -c config/gunicorn
I can then view it going to:
http://127.0.0.1:8000/resources/
I would now like to try hosting it so that other PCs can access this.
Gunicorn is wsgi http server. It is best to use Gunicorn behind HTTP proxy server. We strongly advise you to use nginx.
# http://gunicorn.org/#deployment
Although there are many HTTP proxies available, we strongly advise that you use Nginx. If you choose another proxy server you need to make sure that it buffers slow clients when you use default Gunicorn workers. Without this buffering Gunicorn will be easily susceptible to denial-of-service attacks.
# http://docs.gunicorn.org/en/latest/deploy.html
Of course not. You can use lighttpd or any other web server that supports WSGI, SCGI, FastCGI or AJP. You may refer to this python documentation and django documentation, and these two questions on stackoverflow: Cleanest & Fastest server setup for Django, Differences and uses between WSGI, CGI, FastCGI, and mod_python in regards to Python? might be also helpful.
You don't need a frontend proxy; you can put a standalone webserver like gunicorn directly in production. But there are various reasons why you probably want to use a frontend webserver anyway.
I need to run a simple request/response python module under an
existing system with windows/apache/FastCGI.
All the FastCGI wrappers for python I tried work for Linux only
(they use socket.fromfd() and other such shticks).
Is there a wrapper that runs under windows?
You might find it easier to ditch FastCGI altogether and just run a python webserver on a localhost port. Then just use mod_rewrite to map the apache urls to the internal webserver.
(I started offering FastCGI at my hosting company and to my surprise, nearly everyone ditched it in favor of just running their own web server on the ports I provided them.)
A Django bug suggests that python-fastcgi will work for you, and its PyPI page reports that it works on Windows.
I'd suggest mod_python or mod_wsgi.