The webserver built in to Moya wasn't intended for a production environment. To deploy a Moya site on the internet, we need to use an external webserver which ensures that your site is scalable to a large number of visitors.
Moya uses WSGI to serve a project with an external http (web) server. WSGI is the standard way of interfacing with Python web applications and there should be an adapter for your favorite front-end web server.
The WSGI spec requires that a site provides a Python file which exposes a WSGI application object (not to be confused with Moya's applications). If you created your project with moya start you should find a file called wsgi.py
in the top level of your project directory. This Python file should look something like the following:
from moya.wsgi import Applicationapplication = Application('./', 'production.ini', server='main', logging='prodlogging.ini')
This tells the Moya to read the project from ./
using settings from production.ini
, and to serve the <server> with a docname of main
. It also tells Moya to use logging settings from a file called prodlogging.ini
. Unless you want to expose multiple servers from the same project – which is entirely possible – you will be unlikely to change these parameters.
Configuring your http server is beyond the scope of this project: please see the server's documentation (or google) for details.
You will probably want to use different database settings for a project in production than you have been using for development. You should put these in production.ini
.
You can test your production settings by running a development server and using the -i switch to point at the production settings. For example:
$ moya runserver -i production.ini
It is often worthwhile letting an http server, such as Apache or Nginx, serve your static files. This is because modern http servers are very good at serving static files and it is more efficient to leave Moya serving just dynamic requests.
Unfortunately such webservers won't be aware of Moya's virtual filesystems and will require that all the static files are in a single directory. If you want to serve your static media in this way, you will first have to copy the media to a single location. You can do this fairly simply with the fs subcommand. For example, you can copy everything in the media
file system to a directory called staticmedia
with the following:
$ moya fs media --copy ./staticmedia
You will need to do this every time your media changes.