Python Flask应用程序无法使用mod_wsgi(Apache)查找虚拟环境

时间:2019-12-17 16:50:36

标签: python apache flask mod-wsgi

我是linux和apache的新手,我接管了一个flask应用程序,该应用程序似乎无法找到在配置文件中定义为python-home = / var / www / html / admin_api的虚拟环境/ reporting_module / venv。我无法找到有关Stackoverflow的已回答问题,该问题可以完全解释我的问题。

wsgi文件

import sys
import logging
import os
logging.basicConfig(filename='/var/www/html/admin_api/admin_mod_wsgi.log')
if sys.version_info[0] < 3:
    raise Exception('not using Python3 using:"%s"' %sys.version_info)

sys.path.insert(0,"/var/www/html/admin_api/")
sys.path.insert(0, "/var/www/html/admin_api/reporting_module/")
try:
    from reporting_module.admin_api import application
    application.secret_key = '****************************'
    os.chdir("/var/www/html/admin_api/reporting_module/")
except Exception as e:
    msg = f"system info {sys.version_info} \n path: {sys.path} \n {str(e)}"
    raise Exception(msg)

初始化 .py文件

from flask import Flask
from flask_mail import Mail
import threading
from app import pkg
from app import forms
from app import config
import os
from flask import Flask
from flask_mail import Mail
from celery import Celery 
from dotenv import find_dotenv, load_dotenv


load_dotenv('.env', verbose=True)

app = Flask(__name__)

# celery requires some kind of broker backend, basically this is either redids or RabbitMq as far as I know
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'

celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
celery.config_from_object('app.celeryconfig')
celery.conf.update(app.config)

TaskBase = celery.Task

class ContextTask(TaskBase):
    abstract = True
    def __call__(self, *args, **kwargs):
        with app.app_context():
            return TaskBase.__call__(self, *args, **kwargs)

celery.Task = ContextTask

app.config.from_object(config.DevConfig)
mail = Mail(app)

from app import routes

/etc/apache2/sites-enabled/reports.conf文件

<VirtualHost *:80>

                ServerName reports.*******.com 
                ServerAdmin **********@********.com
                DocumentRoot /var/www/html/admin_api/
                WSGIApplicationGroup /var/www/html/admin_api/reporting_module/venv/bin/python
                WSGIDaemonProcess reporting_module user=www-data processes=2 threads=5 display-name=%{GROUP} python-home=/var/www/html/admin_api/reporting_module/venv home=/var/www/html/admin_api request-timeout=600

                WSGIProcessGroup reporting_module
                WSGIScriptAlias / /var/www/html/admin_api/admin_api.wsgi
               # *Every* Alias must have a directory block
                <Directory /var/www/html/admin_api>
                           Options Indexes FollowSymLinks
                           AllowOverride None
                           Require all granted  
                </Directory>
                <Directory /var/www/html/admin_api/reporting_module/app>
                           Options Indexes FollowSymLinks
                           AllowOverride None
                           Require all granted  
                </Directory>
                Alias /static  /var/www/html/admin_api/reporting_module/app/static
                <Directory var/www/html/admin_api/reporting-module/app/static/>
                           Options Indexes FollowSymLinks
                           AllowOverride None
                           Require all granted  
                </Directory>
                Alias /static/css  /var/www/html/admin_api/reporting_module/app/static/css
                <Directory var/www/html/admin_api/reporting-module/app/static/css>
                           Options Indexes FollowSymLinks
                           AllowOverride None
                           Require all granted  
                </Directory>


                CustomLog ${APACHE_LOG_DIR}/adminAPI-access.log combined
                ErrorLog ${APACHE_LOG_DIR}/adminAPI-error.log
                LogLevel warn
</VirtualHost>

任何有关如何解决此问题或我能想到的其他问题的想法,将不胜感激。

0 个答案:

没有答案