支援 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>