Flask: Apache Httpd font end and websocket support - python

I am developing an application where I am using a flask container with websocket support for streaming data to the server. I am using https://github.com/kennethreitz/flask-sockets for this purpose. I use gunicorn to start the server and all is good.
My question is can I deploy a production server using Apache httpd? I have seen numerous posts that suggest using Nginx as the web server front end. I want a cross platform (windows and linux) solution. However, it appears nginx only has an experimental windows port (for windows 7). On the other hand, Apache httpd has a stable windows port so if possible I want to go that route. Has anybody successfully deployed Flask websockets with Apache httpd and if so I would love to get some pointers to how to go about doing so. If this is not possible or does not work well, I would appreciate some advice to that effect as well.
Thank you in advance for your replies.
Regards,
Ranga

Unfortunately, at the current time, it will not be very easy to make such an application cross-platform.
Apache supports proxying to a web-socket-enabled server, but it only runs in POSIX-compliant environments. (Apache's evented multi-process module also only runs on systems with Unix-like {k,e}poll support).
IIS 8, on the other hand, ships with support for WebSockets and is Windows-native. However, getting Python + IIS running together is either ridiculously complex or else relies on horrendously out-of-date software.
Gunicorn will support Windows in R-20; which will be released on a yet-to-be-named-date. Once that is released you should be able to run Gunicorn as a Windows Service.

Related

Easiest way to configure nginx to run CGI Perl and Python for few scripts that under very low use?

I am looking for a simple nginx setup that runs Perl and Python scripts that are under very low load (99% of time a single user browsing them and no mode than 100 request/day).
Because the server is running on a AWS under a micro instance I am looking for something that has a very low memory footprint.
Update: I'm running an Ubuntu 12.04 on it and after installing nginx which does not contain the embedded perl module, I installed nginx-extras which is supposed to contain it. Still I have no idea how to enable it, also strage it did not complain about the nginx package.
nginx does not support (by design) CGIs.
You need an application server for managing them:
http://projects.unbit.it/uwsgi/wiki/CGI
(it is pretty advanced so be prepared for some study, but you should be able to reach your objective)

How to run nginx + python (without django)

I want to have simple program in python that can process different requests (POST, GET, MULTIPART-FORMDATA). I don't want to use a complete framework.
I basically need to be able to get GET and POST params - probably (but not necessarily) in a way similar to PHP. To get some other SERVER variables like REQUEST_URI, QUERY, etc.
I have installed nginx successfully, but I've failed to find a good example on how to do the rest. So a simple tutorial or any directions and ideas on how to setup nginx to run certain python process for certain virtual host would be most welcome!
Although you can make Python run a webserver by itself with wsgiref, I would recommend using one of the many Python webservers and/or web frameworks around. For pure and simple Python webhosting we have several options available:
gunicorn
tornado
twisted
uwsgi
cherrypy
If you're looking for more features you can look at some web frameworks:
werkzeug
flask
masonite
cherrypy (yes, cherrypy is both a webserver and a framework)
django (for completeness, I know that was not the purpose of the question)
You should look into using Flask -- it's an extremely lightweight interface to a WSGI server (werkzeug) which also includes a templating library, should you ever want to use one. But you can totally ignore it if you'd like.
You can use thttpd. It is a lightweight wsgi server for running cgi scripts. It works well with nginx. How to setup thttpd with Nginx is detailed here: http://nginxlibrary.com/running-cgi-scripts-using-thttpd/
All the same you must use wsgi server, as nginx does not support fully this protocol.

Django: how to publish an app

I have developed an app using Django 1.1.1 and python 2.7.1. I want to publish it on a commercial website, but not sure which one.
the app works fine on the apache server running on my local machine, however, before investing on a host, I want to be sure that I have the necessary requirements, so if it matters, what are the possible hosts I can use?
I use Apache 2.2 with python 2.7.1 on my local machine running with Django 1.1.1. I use the Windows OS. I tried looking at linode but they don't have a documentation for Windows users in using Django and mod_wsgi, so does it even matter?
This is the first time I try to publish on a commercial site, so I don't want to invest on a host and then find myself stuck and not knowing how to upload my Django app.
Thanks,
You can follow the docs on linode just fine, it doesn't matter that you're a Windows user, the app will be deployed on a linux box.
You can also try a shared hosting solution, that will run django right way, without any need to configure and setup a new machine. My personal recommendation is http://www.webfaction.com/ . Another alternative is https://www.djangy.com/.

A production ready server to serve django on win32

I'd like to serve django application on windows XP/Vista.
The application is an at hoc web interface to a windows program so it won't be put under heavy load (around 100 requests per second).
Do you know any small servers that can be easily deployed on windows to serve a django app? (IIS is not an option as the app should work on all versions of windows)
cherrypy includes a good server. Here's how you set it up to work with django and some benchmarks.
twisted.web has wsgi support and that could be used to run your django application. Here's how you do it.
In fact any wsgi server will do. Here's one more example, this time using spawning:
$ spawn --factory=spawning.django_factory.config_factory mysite.settings
And for using paste, the info is gathered here.
Of course, you could use apache with mod_wsgi. It would be just another wsgi server. Here are the setup instructions.
If you want to give Apache a go, check out XAMPP to see if it'll work for you. You can do a lightweight (read: no installation) "installation." Of course, you'll also want to install mod_python to run Django. This post may help you set everything up. (Note: I have not used python/Django with XAMPP myself.)
Edit: Before someone points this out, XAMPP is not generally a production-ready tool. It's simply a useful way to see whether Apache will work for you. Also, I saw that you're using SQLite after the fact.
Why not Apache ?
Nokia have developed a scaled down version of apache to run on their mobile phones. It supports python.
http://research.nokia.com/research/projects/mobile-web-server/
Also do you need anything else such as database support etc?

Python as FastCGI under windows and apache

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.

Categories

Resources