# mod_wsgi (Apache)
If you are using the [Apache](http://httpd.apache.org/) [http://httpd.apache.org/] webserver you should consider using [mod_wsgi](http://code.google.com/p/modwsgi/) [http://code.google.com/p/modwsgi/].
### Installing mod_wsgi
If you don't have mod_wsgi installed yet you have to either install it usinga package manager or compile it yourself.
The mod_wsgi [installation instructions](http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide) [http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide] cover installation instructions forsource installations on UNIX systems.
If you are using ubuntu / debian you can apt-get it and activate it as follows:
~~~
# apt-get install libapache2-mod-wsgi
~~~
On FreeBSD install mod_wsgi by compiling the www/mod_wsgi port or by usingpkg_add:
~~~
# pkg_add -r mod_wsgi
~~~
If you are using pkgsrc you can install mod_wsgi by compiling thewww/ap2-wsgi package.
If you encounter segfaulting child processes after the first apache reload youcan safely ignore them. Just restart the server.
### Creating a .wsgi file
To run your application you need a yourapplication.wsgi file. This filecontains the code mod_wsgi is executing on startup to get the applicationobject. The object called application in that file is then used asapplication.
For most applications the following file should be sufficient:
~~~
from yourapplication import make_app
application = make_app()
~~~
If you don't have a factory function for application creation but a singletoninstance you can directly import that one as application.
Store that file somewhere where you will find it again (eg:/var/www/yourapplication) and make sure that yourapplication and allthe libraries that are in use are on the python load path. If you don'twant to install it system wide consider using a [virtual python](http://pypi.python.org/pypi/virtualenv) [http://pypi.python.org/pypi/virtualenv] instance.
### Configuring Apache
The last thing you have to do is to create an Apache configuration file foryour application. In this example we are telling mod_wsgi to execute theapplication under a different user for security reasons:
~~~
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess yourapplication user=user1 group=group1 processes=2 threads=5
WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi
<Directory /var/www/yourapplication>
WSGIProcessGroup yourapplication
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
~~~
For more information consult the [mod_wsgi wiki](http://code.google.com/p/modwsgi/wiki/) [http://code.google.com/p/modwsgi/wiki/].
- 开始
- Werkzeug 文档概览
- 安装
- 过渡到 Werkzeug 1.0
- Werkzeug 教程
- API 标准
- 快速开始
- Python 3 Notes
- 服务和测试
- Debugging Applications
- 在服务器运行 WSGI 应用
- 单元测试
- 参考
- Request / Response Objects
- URL Routing
- WSGI Helpers
- HTTP Utilities
- Data Structures
- Utilities
- Context Locals
- Middlewares
- HTTP Exceptions
- 部署
- CGI
- mod_wsgi (Apache)
- FastCGI
- HTTP Proxying
- 贡献模块
- Atom Syndication
- Sessions
- Secure Cookie
- Cache
- Extra Wrappers
- Iter IO
- Fixers
- WSGI Application Profiler
- Lint Validation Middleware
- 额外说明
- Werkzeug Changelog
- Important Terms
- Unicode
- Dealing with Request Data