Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
673 views
in Technique[技术] by (71.8m points)

apache2 - Flask app on Apache 2 gives internal server error

I get the following error when running my website on apache2/ubuntu:

ModuleNotFoundError: No module named 'FlaskApp'
[Sun Jan 24 23:04:52.381039 2021] [wsgi:error] [pid 25239] [client 190.160.166.19:49593] mod_wsgi (pid=25239): Target WSGI script '/var/www/FlaskApp/flaskapp.wsgi' cannot be loaded as Python module., referer: https://www.publimundo.cl/
[Sun Jan 24 23:04:52.381091 2021] [wsgi:error] [pid 25239] [client 190.160.166.19:49593] mod_wsgi (pid=25239): Exception occurred processing WSGI script '/var/www/FlaskApp/flaskapp.wsgi'., referer: https://www.publimundo.cl/
[Sun Jan 24 23:04:52.381163 2021] [wsgi:error] [pid 25239] [client 190.160.166.19:49593] Traceback (most recent call last):, referer: https://www.publimundo.cl/
[Sun Jan 24 23:04:52.381180 2021] [wsgi:error] [pid 25239] [client 190.160.166.19:49593]   File "/var/www/FlaskApp/flaskapp.wsgi", line 7, in <module>, referer: https://www.publimundo.cl/
[Sun Jan 24 23:04:52.381185 2021] [wsgi:error] [pid 25239] [client 190.160.166.19:49593]     from FlaskApp import app as application, referer: https://www.publimundo.cl/

This is my virtual host configuration:

<VirtualHost *:443>
    ServerAdmin [email protected]
    ServerName www.publimundo.cl

    WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi

    SSLEngine on
    SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
    SSLProtocol all -SSLv2 -SSLv3

    Timeout 300
    KeepAlive On
    MaxKeepAliveRequests 0
    KeepAliveTimeout 20

    ErrorLog /var/log/site_logs/publimundo-error.log
    CustomLog /var/log/site_logs/publimundo-access.log combined

    <Directory "/var/www/FlaskApp">
        AllowOverride All
        Allow from All
        Require all granted
        Options +FollowSymLinks
     </Directory>

    Alias /static /var/www/FlaskApp/publimundo/static
    <Directory "/var/www/FlaskApp/publimundo/static">
        AllowOverride All
        Allow from All
        Require all granted
        Options +FollowSymLinks
     </Directory>

    #Include /etc/letsencrypt/options-ssl-apache.conf
    SSLCertificateFile /etc/letsencrypt/live/publimundo.cl/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/publimundo.cl/privkey.pem
</VirtualHost>

Also the content of flaskapp.wsgi is:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = 'some secret key here'

what can be the root of the problem? I have tried many answers on stackoverflow but did not help.

question from:https://stackoverflow.com/questions/65878358/flask-app-on-apache-2-gives-internal-server-error

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Found my error. The flaskapp.wsgi should be as follows:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp/")

from publimundo import app as application
application.secret_key = 'some secret key here'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...