How running jython on nginx? - django

How running django-jython on FastCGI in Nginx?

Short answer: You can't.
Although nginx can be used as a lightweight web server, its main strength is that it is a very good reverse proxy and it is used primarily in this role.
You'll need to run your application in a servlet container (like tomcat), and then have nginx proxy to it.
See the running django on jython section at the django documentation.

Related

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

Is it a good practice use Django integrated web server behind a proxy?

I implement a Django website behind a NGINX configured as reverse proxy which serve also the static for Django when it is out of debug mode, all this is in a docker-compose app.
I know by read the Django docs they do not recommend to use integrated web server in a production environment (and it is not at the moment), put it behind a reverse proxy is acceptable to avoid security issue or it is the same as expose it directly?
If it is not an acceptable solution, could you suggest any implementation to not use the Django integrated web server?
Consider that the container structure like the following:
Proxy is the NGINX Official image
www1 & www2 are Python3 Official image with Django installed as described here.
database is the Postgres Official image.
Only the Proxy container is exposed to the external world.
Thanks.
I get my answer, I gonna use gunicorn instead the integrated Django web browser.
I had use documentation present here That describe how to configure gunicorn and nginx on the same host, but using http instead linux socket, instead the command to run the Django integrate web server I have just to run gunicorn like this:
gunicorn --workers=4 --bind=0.0.0.0:9000 --access-logfile - --error-logfile - --log-level debug myapp.wsgi:application
with the previous command I also get logs managed by container.
Off course I also add gunicorn in the requirement file.
I hope this question will help also some one else.

Which docker container choose for a django application in production

I am new to docker.
I saw existing images like one called "django" on docker hub.
It sounds great but i see this image is working with django integrated server on 8000 http port.
So i am wondering if this docker prebuilt image is for development purpose instead of production.
Which prebuilt image should i use for production ?
Thanks
The django image on the Hub is an official repository, which means it's curated, security checked and maintained by Docker - so it's a trustworthy source.
You wouldn't use it on its own though. You'd run your web app in a Django container and then front it with a reverse proxy like Nginx, running in another container. The outside world talks to your proxy, and your proxy talks to Django.
There are detailed docs on using Nginx as a reverse proxy for Django.

Alternative application server for Bosun

As far as I understand, fiware-bosun uses Django server. However, is it possible to deploy it using a different application server (e.g. Apache)?
Fiware-bosun is compound by two different modules:
Fiware-cloto: The Rule engine which uses Django server with WSGI.
Fiware-facts: the server to process the incoming facts, which uses Flask + Gevent with WSGI.
Both components are recommended to be deployed using gunicorn and you could also add supervisord and Nginx over this layer.
However, of course you can deploy the rule engine using any other application server that supports WSGI (e.g. Apache + mod_wsgi).

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.