支持 Apache 站点的 WSGI 配置
在内置的 werkzeug 服务器上使用 Apache 的优点是 Apache 是多线程的,这意味着可以同时与应用程序建立多个连接。这在前端使用 XmlHttpRequest (AJAX)的应用程序中尤其有用。
/etc/apache2/sites-available/050-my-application.conf (如果没有托管在共享的 Web 服务器上,则为默认的 apache 配置)
<VirtualHost *:80>
ServerName my-application.org
ServerAdmin admin@my-application.org
# Must be set, but can be anything unless you want to serve static files
DocumentRoot /var/www/html
# Logs for your application will go to the directory as specified:
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# WSGI applications run as a daemon process, and need a specified user, group
# and an allocated number of thread workers. This will determine the number
# of simultaneous connections available.
WSGIDaemonProcess my-application user=username group=username threads=12
# The WSGIScriptAlias should redirect / to your application wrapper:
WSGIScriptAlias / /path/to/my-application/my-application.wsgi
# and set up Directory access permissions for the application:
<Directory /path/to/my-application>
WSGIProcessGroup my-application
WSGIApplicationGroup %{GLOBAL}
AllowOverride none
Require all granted
</Directory>
</VirtualHost>