I know it might be a bad design but since we are developing the django website on our laptops which runs Win7, I thought it would be better to run django on a Windows platform only in production.
(Laptop is not powerful enough to run a Unix VM inside and our Unix team doesn't provide any Unix server with UI access (Only Putty) so using an IDE is impossible on Unix.)
I have deployed django with gunicorn and nginx on a Linux server very easily, but this time I have to deploy django on a Windows server with Apache on another Unix server (I know it sucks).
Our middleware team is asking(forcing) to run django components on a separate server so that they can manage their Apache (on Unix) instance comfortably. As far as I understand, Apache and django should reside on the same server for mod_wsgi to work.
Is this possible to keep Apache on a Unix machine and make a django website run from a Windows machine?
If not, what are the best possible solutions in my case? (Switch django on Unix? Use waitress on Django windows? Do not separate Apache and Django? etc.)
Regards,
Aditya
Try deploying on IIS instead, as it is the native Web Server on Windows Servers.
Checkout the django-windowsauth package, you can use it to deploy your project to IIS using few simple commands. https://github.com/danyi1212/django-windowsauth.
The best thing in my modest point of view is to create a unix docker image of your project
Related
I'm moving away from WordPress and into bespoke Python apps.
I've settled on Django as my Python framework, my only problems at the moment are concerning hosting. My current shared hosting environment is great for WordPress (WHM on CloudLinux), but serving Django on Apache/cPanel appears to be hit and miss, although I haven't tried it as yet with my new hosting company. - who have Python enabled in cPanel.
What is the easiest way for me to set up a VPS to run a hosting environment for say, twenty websites? I develop everything in a virtualenv, but I have no experience in running Django in a production environment as yet. I would assume that venv isn't secure enough or has scalability issues? I've read some things about people using Docker to set up separate Django instances on a VPS, but I'm not sure whether they wrote their own management system.
It's my understanding that each instance Python/Django needs uWSGI and Nginx residing within that virtual container? I'm looking for a simple and robust solution to host 20 Django sites on a VPS - is there an out of the box solution? I'm also happy to develop one and set up a VPS if I'm pointed in the right direction.
Any wisdom would be gratefully accepted.
Andy :)
Traditional approach
Virtualenv is good enough and perfectly ready for production use. You can have multiple virtualenv for multiple projects on the same VM.
If you have multiple database engines for multiple projects. Like, MySQL for one, PostgreSQL for another something like this then you just need to set up each individually.
Install Nginx and configure each according to project.
Install supervisor to manage(restart/start/stop) each project individually.
Anything that required by the project.
Here it has a huge drawback. Because you can't use different versions on your database engine for a different project in an easy way. So, containerization is highly recommended.
For simple and robust solution,
Use Docker(docker-compose) for local and production deployment.
Configure uWsgi with Nginx(Available on docker.)
Create a CI/CD pipeline with any tool like Jenkins.
Monitor your projects using any good tool like Raygun.
That's it.
I created a bash script that deploys as many websites as you want on your server. It automatically installs all dependencies on your server, creates a virtual environment, configure Gunicorn, Nginx, and a database for Django, etc. Check it out:
https://github.com/jdbit/django-auto-deploy
I have an Linux instance running on Google Compute Engine. I installed pip and django on it and cloned a Django project that I worked on locally. Like I would on localhost I ran my app like so: python3 manage.py runserver 0.0.0.0:8080, and my server was up and running with no problems. I read online on how WSGI servers are required for python apps to run well on servers however I don't see why I would need something like gunicorn to run my app
Here's what the documentation for runserver says:
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
Django's runserver is itself a WSGI server, but it's aimed at being easy for developers to use.
Production WSGI servers like uWSGI and Gunicorn have performance and production environments in mind. They handle concurrency better, they are faster, and are built to withstand malicious users, not just developers.
I have an application setup in Flask and running on localhost in a Windows environment. All of the tutorials I have read said to not use the default Flask server in production.
The production servers Gunicorn and uWSGI both only work in Unix. Is there a way to run either one of those through Windows?
Or do I need to switch the project over to a UNIX development environment?
There's many WSGI servers you can use to serve a Flask application. If you really need to deploy it to Windows, then I did find NWSGI, which might be worth a look.
I think it's fair to say that WSGI servers are few and far between on Windows, as this list only mentioned NWSGI. Unless you have a very good reason to deploy to Windows, I think you're probably better off opting for a *nix environment.
Even with this question answered I wanted to add that you can run wsgi apps on IIS
which is a production level web server.
the easiest example is how flask can run on azure (IIS) but I saw a link explaining it even better https://heejune.me/2015/04/22/running-python-flask-on-a-local-iis-not-azure-with-wfastcgi-py/
Waitress is a pure python solution for both Windows and Nix platforms that is no more complex to set up than the development server.
We have an application written in django. We are trying a deployment scenario which will have one docker running apache, the second docker running django and the third docker running the DB server. In most of the documentation it is mentioned that apache and django will sit on the same machine (django in virtualenv to be precise), is there any way we can ask apache to talk to mod_wsgi sitting on a remote machine which has the django application?
mod_wsgi would be the wrong technology if you want to do this. It runs as part of Apache itself, so there literally is nothing to run in the Django container.
A better way would be to use gunicorn to run Django in one container, and have the other running the webserver as a proxy - you could use Apache for this, although it's more common to use nginx.
I have a locally developed Pylons application. I also have hosting provider with SSH access, python 2.6 and have set a virtual environment on the server. After that using easy_install I have installed Pylons and achieved to execute it on port XXXX. The problem is that the firewall of the server is blocking any port other from 80 (the port of the Apache http). Can I redirect Apache to forward to my Pylons server?
If you are in jail or virtual container where running your isolate instance of apache, just kill it.
You can see process list by execute 'top' utility.
You need to configure a virtualhost in apache so that it uses wsgi.
There's a plenty of topics in stackoverflow about this, such as
Trying to get Pyramid running under Apache + mod_wsgi but it's failing
(you can follow the link in the first sentence).
If you cannot use mod_wsgi, that you can try with mod_rewrite or mod_proxy, which have worse performance. If you cannot change the apache configuration, ask you provider, or start thinking about changing provider.