On 06/03/2015, at 6:55 AM, Ronny Pfannschmidt <[email protected]> 
wrote:

> in reference to my tweet, 
> 
> unlike other deployments, mod_wsgi cant be configured with a python home and 
> a entrypoint
> 
> that makes various forms of deployment a bit more painfull, i already saw the 
> mod_wsgi express thing and
>  i'm curious about how deployments would look with it as well

Now for the second part about mod_wsgi-express.

What mod_wsgi-express is ultimately intended for is a simple way of getting 
people up and running who don't have overly strange requirements or a need to 
be running multiple Python web sites at the same time, although there are ways 
of doing the latter if need be, even with different Python versions. Can 
explain this another time if people interested.

So what mod_wsgi-express does for you is generate all the Apache configuration 
for you, based on minimal command line options. The Apache configuration 
generated and how mod_wsgi is setup is based on my knowledge of what is the 
best way for doing things. That way you don't have to fumble around making 
guesses as to what to change and I give you a really good starting point which 
is going to be much better than any default Linux distribution Apache 
configuration when it comes to running Python web sites.

So in the simplest case if you had a simple WSGI script file all you would have 
to do is run:

    mod_wsgi-express start-server hello.wsgi

This would by default run on port 8000.

If you wanted to use mod_wsgi-express to run up your application on port 80 and 
replace the default Apache configuration file the system then it is better to 
use mod_wsgi-express to generate the configuration needed but not actually 
start the server straight away.

In this case you would run something like:

    sudo mod_wsgi-express setup-server --server-root 
/etc/mod_wsgi-www.example.com-80 --log-directory /var/log/apache2 --user 
www-data --group www-data --port 80 hello.wsgi

This would generate various files in /etc/mod_wsgi-www.example.com-80, the key 
one being 'apachectl'.

All that is then required is to setup system init scripts to run 'apachectl 
start' and 'apachectl stop' as appropriate.

I want to have mod_wsgi-express even generate the skeletons for the system init 
scripts so you can copy/link them into the right place and not even have to 
worry about creating them, but I possibly need a bit of guidance on that one to 
handle all the different init systems and when I put out a query for people who 
could help, got no response. I do intend to look at that again soon though 
myself.

As to how complicated of a system can mod_wsgi-express handle setting up, well 
to run a secure web site you could use:

    sudo mod_wsgi-express setup-server --server-root 
/etc/mod_wsgi-www.example.com-443 --log-directory /var/log/apache2 --user 
www-data --group www-data \
        --https-port 8443 --https-only --ssl-certificate server --server-name 
www.example.com hello.wsgi

In the directory you would need your 'server.crt' and 'server.key' file with 
option of --ssl-certificate used. Unreleased version allows you to specify the 
.crt and .key files with separate options.

So mod_wsgi-express supports all sorts of stuff for secure web sites and lots 
more common stuff that people would setup in Apache. Even handles things like 
log file rotations, access log with different formats etc etc.

Another example is static file handling. If you had a directory which had 
favicon.ico, robots.txt or other static file assets in it, you could do:

    mod_wsgi-express start-server --document-root htdocs hello.wsgi

What will happen is that any static files are given priority and if they exist 
are served up. If there is no static file mapped by the URL, then the request 
would instead be handled by the WSGI application.

If you have specific directories of static files that need to be hosted at a 
specific sub URL, such as with Django, you can use:

    mod_wsgi-express start-server --working-directory example --url-alias 
/static example/htdocs --application-type module example.wsgi

This presumes you were running it from the directory above where your Django 
project is and that 'example/htdocs' was where collectstatic placed the files.

Of note in this example is that rather than specify a WSGI script file, you can 
say the application is actually specified by a module. Thus 'example.wsgi' here 
is actually specifying the module path to 'example/wsgi.py' after the working 
directory had been setup properly. The mod_wsgi-express is effectively 
generating a WSGI script file for you that in turn imports the module for the 
application.

One can even integrate mod_wsgi-express into Django admin commands so you can 
simply do:

    python manage.py runmodwsgi

The runmodwsgi management command will then make sure all the options necessary 
for static file assets is set up and the WSGI application for Django is 
imported okay.

Now mod_wsgi-express isn't just for trying to run production sites either. The 
fact that you can run it on the command line means you can use it for 
development as well.

Want the reloading of Django development server, use:

    python manage.py runmodwsgi --reload-on-changes

There is also a debug mode where it will run in single process mode and allow 
you to enable Python debugger automatically.

    python manage.py runmodwsgi --debug-mode --enable-debugger

When an unhanded exception occurs in a request that gets back to the WSGI 
application top level, you will be thrown into pdb automatically.

There are also debug modes options for code coverage, profiling and recording 
of requests for offline analysis.

There is even an option to run up Apache under gdb to try and track down 
process crashes due to C extension modules.

The mod_wsgi-express package therefore covers quite a lot of range. It can be 
used for development, to quickly run WSGI applications on the command line to 
production grade applications started on system startup.

It is therefore much more versatile than any other WSGI server in that respect 
with its easy options for a range of builtin functionality.

One of my favourites is that through a special application type you can even 
use it as a quick alternative to host up static files, replacing 'python -m 
SimpleHTTPServer' with a real server, one that can be very easily secured with 
SSL if need be. Thus:

    mod_wsgi-express start-server --application-type static --directory-listing

As a bit of a joke to prove it could be done I even added an option:

    mod_wsgi-express start-server --document-root static --with-php5 hello.wsgi

If the Apache being used has PHP module installed and setup, you can even 
easily mix a PHP application defined by php files in the static directory with 
the WSGI application.

Finally, as to PYTHONHOME and mod_wsgi-express, it will correctly use whatever 
Python virtual environment or installation you had it installed it. So it will 
just do the right thing and you don't have to worry about it.

Graham


    

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to