..
.. META INFORMATION OF TRANSLATION
..
.. $TranslationStatus: Done, waiting for revision. $
.. $OriginalRevision: 10838 $
.. $TranslationAuthors: Walter Cruz $
..
.. INFO OF THIS FILE (DO NOT EDIT! UPDATED BY SUBVERSION)
..
.. $HeadURL$
.. $LastChangedRevision$
.. $LastChangedBy$
.. $LastChangedDate$
..
==========================================
Como usar o Django com o Apache e mod_wsgi
==========================================
A implantação do Django com Apache_ e `mod_wsgi`_ é a forma recomendada de ter o
Django funcionando em produção.
.. _Apache: http://httpd.apache.org/
.. _mod_wsgi: http://code.google.com/p/modwsgi/
O mod_wsgi é um módulo do Apache que pode ser usado para hospedar qualquer aplicação Python
que suporte a `Interface WSGI do Python`_, incluindo o Django. O Django irá funcionar
com qualquer versão do Apache que suporte o mod_wsgi.
.. _interface wsgi do python: http://www.python.org/dev/peps/pep-0333/
A `documentação oficial do mod_wsgi`_ é fantástica; é sua fonte para todos
os detalhes sobre como usar o mod_wsgi. você provavalmente irá querer iniciar com a
`documentação de instalação e configuração`_.
.. _documentação oficial do mod_wsgi: http://code.google.com/p/modwsgi/
.. _documentação de instalação e configuração: http://code.google.com/p/modwsgi/wiki/InstallationInstructions
Configuração Básica
===================
Uma vez que você tenha o mod_wsgi instalado e ativado, edite o seu arquivo ``httpd.conf``
e adicione::
WSGIScriptAlias / /path/to/mysite/apache/django.wsgi
A primeira parte acima é a url na qual você estará servindo sua aplicação (``/``
indica a url raiz), e a segunda parte é a localização de um "arquivo WSGI" -- veja
abaixo -- no seu sistema, normalmente dentro do seu projeto. Isso diz ao Apache
para servir quaisquer requisições abaixo de dada URL usando a aplicação WSGI definida por aquele arquivo.
Em seguida, vamos efetivamente criar essa aplicação WSGI, então crie o arquivo
mencionado na segunda parte da linha ``WSGIScriptAlias`` e adicione::
import os
import sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Se o seu projeto não está no ``PYTHONPATH`` padrão você pode adicionar::
path = '/path/to/mysite'
if path not in sys.path:
sys.path.append(path)
logo abaixo das linhas de ``import.sys`` para colocar o seu projeto no path. Lembre-se de
substituir o 'mysite.settings' como seu arquivo de configurações correto, and '/path/to/mysite'
with your own project's location.
.. _serving-files:
Serving files
=============
Django doesn't serve files itself; it leaves that job to whichever Web
server you choose.
We recommend using a separate Web server -- i.e., one that's not also running
Django -- for serving media. Here are some good choices:
* lighttpd_
* Nginx_
* TUX_
* A stripped-down version of Apache_
* Cherokee_
If, however, you have no option but to serve media files on the same Apache
``VirtualHost`` as Django, you can set up Apache to serve some URLs as
static media, and others using the mod_wsgi interface to Django.
This example sets up Django at the site root, but explicitly serves
``robots.txt``, ``favicon.ico``, any CSS file, and anything in the
``/static/`` and ``/media/`` URL space as a static file. All other URLs
will be served using mod_wsgi::
Alias /robots.txt /usr/local/wsgi/static/robots.txt
Alias /favicon.ico /usr/local/wsgi/static/favicon.ico
AliasMatch ^/([^/]*\.css) /usr/local/wsgi/static/styles/$1
Alias /media/ /usr/local/wsgi/media/
Alias /static/ /usr/local/wsgi/static/
Order deny,allow
Allow from all
Order deny,allow
Allow from all
WSGIScriptAlias / /usr/local/wsgi/scripts/django.wsgi
Order allow,deny
Allow from all
.. _lighttpd: http://www.lighttpd.net/
.. _Nginx: http://wiki.nginx.org/Main
.. _TUX: http://en.wikipedia.org/wiki/TUX_web_server
.. _Apache: http://httpd.apache.org/
.. _Cherokee: http://www.cherokee-project.com/
.. More details on configuring a mod_wsgi site to serve static files can be found
.. in the mod_wsgi documentation on `hosting static files`_.
.. _hosting static files: http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files
.. _serving-the-admin-files:
Serving the admin files
=======================
Note that the Django development server automagically serves the static files
of the admin app, but this is not the case when you use any other server
arrangement. You're responsible for setting up Apache, or whichever media
server you're using, to serve the admin files.
The admin files live in (:file:`django/contrib/admin/static/admin`) of the
Django distribution.
We **strongly** recommend using :mod:`django.contrib.staticfiles` to handle
the admin files, but here are two other approaches:
1. Create a symbolic link to the admin static files from within your
document root.
2. Or, copy the admin static files so that they live within your Apache
document root.
Detalhes
========
Para maiores detalhes, veja a `documentação do mod_wsgi`_, que explica os itens acima em
maior detalhamento, e lhe dá todas as possibilidades de opções que você tem
ao fazer uma implantação no mod_wsgi.
.. _documentação do mod_wsgi: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango