Apache和mod_wsgi

时间:2017-10-26 21:16:10

标签: apache flask mod-wsgi wsgi

我有一个Python webapp(使用Flask),我使用Apache和mod_wsgi。现在,只要我启动Apache,我就会看到有4个Apache进程已经启动(参见下面的htop截图)。 enter image description here

现在,在对应用程序发出POST请求后,我看到其中一个进程正常工作,其他进程无效。接下来的几个POST请求(2到5个请求之间)仍然会发送到第一个进程,但之后会使用第二个进程,这会让我遇到内存问题。你能告诉我怎么能阻止这个吗?这是我的Apache conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>

    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ServerAdmin admin@mydomain.com
    DocumentRoot /var/www/html


    WSGIScriptAlias /myapp /var/www/wsgi-scripts/myapp.wsgi


    ErrorLog ${APACHE_LOG_DIR}/myapp.error.log
    CustomLog ${APACHE_LOG_DIR}/myapp.access.log combined

    # I tried with commenting and un-commenting this, same result
    <Directory /var/www/wsgi-scripts>
        Order allow,deny
        Allow from all
    </Directory>

    RewriteEngine on
    tps://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
    SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

1 个答案:

答案 0 :(得分:1)

不要使用嵌入模式:

然后继续完全禁用嵌入式模式,因此Python解释器甚至在Apache子工作进程中都没有初始化。