repair apache mod_wsgi configuration
mod_wsgi is able to pass variables set through SetEnv only through `environ` variable. Those will not be available in the os.environ. In addition modify documentation to better describe wsgi_sqlite usage with virtualenv Co-Authored-By: David Moreau Simard <dmsimard@redhat.com> Co-Authored-By: Artem Goncharov <artem.goncharov@gmail.com> Change-Id: I06a1d6be2737fd18d8e907a771ab97d652ebdf7f
This commit is contained in:
parent
618eafa549
commit
93ecffcd9e
|
@ -51,22 +51,6 @@ import shutil
|
|||
import six
|
||||
import time
|
||||
|
||||
if (int(os.getenv('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and
|
||||
os.getenv('ARA_WSGI_VIRTUALENV_PATH')):
|
||||
# Backwards compatibility, we did not always suffix activate_this.py
|
||||
activate_this = os.getenv('ARA_WSGI_VIRTUALENV_PATH')
|
||||
if 'activate_this.py' not in activate_this:
|
||||
activate_this = os.path.join(activate_this, 'bin/activate_this.py')
|
||||
|
||||
if six.PY2:
|
||||
execfile(activate_this, dict(__file__=activate_this)) # nosec
|
||||
else:
|
||||
exec(open(activate_this).read()) # nosec
|
||||
|
||||
TMPDIR_MAX_AGE = int(os.getenv('ARA_WSGI_TMPDIR_MAX_AGE', 3600))
|
||||
LOG_ROOT = os.getenv('ARA_WSGI_LOG_ROOT', '/srv/static/logs')
|
||||
DATABASE_DIRECTORY = os.getenv('ARA_WSGI_DATABASE_DIRECTORY', 'ara-report')
|
||||
|
||||
logger = logging.getLogger('ara.wsgi_sqlite')
|
||||
if not logger.handlers:
|
||||
logging.basicConfig(format='%(name)s:%(levelname)s:%(message)s')
|
||||
|
@ -86,6 +70,26 @@ def bad_request(environ, start_response, message):
|
|||
|
||||
|
||||
def application(environ, start_response):
|
||||
# Apache SetEnv variables are passed only in environ variable
|
||||
if (int(environ.get('ARA_WSGI_USE_VIRTUALENV', 0)) == 1 and
|
||||
environ.get('ARA_WSGI_VIRTUALENV_PATH')):
|
||||
# Backwards compatibility, we did not always suffix activate_this.py
|
||||
activate_this = environ.get('ARA_WSGI_VIRTUALENV_PATH')
|
||||
if 'activate_this.py' not in activate_this:
|
||||
activate_this = os.path.join(activate_this, 'bin/activate_this.py')
|
||||
|
||||
if six.PY2:
|
||||
execfile(activate_this, dict(__file__=activate_this)) # nosec
|
||||
else:
|
||||
exec(open(activate_this).read()) # nosec
|
||||
|
||||
TMPDIR_MAX_AGE = int(environ.get('ARA_WSGI_TMPDIR_MAX_AGE', 3600))
|
||||
LOG_ROOT = environ.get('ARA_WSGI_LOG_ROOT', '/srv/static/logs')
|
||||
DATABASE_DIRECTORY = environ.get(
|
||||
'ARA_WSGI_DATABASE_DIRECTORY',
|
||||
'ara-report'
|
||||
)
|
||||
|
||||
request = environ['REQUEST_URI']
|
||||
match = re.search('/(?P<path>.*/{}/)'.format(DATABASE_DIRECTORY), request)
|
||||
if not match:
|
||||
|
|
|
@ -110,15 +110,55 @@ middleware. In order to do so, the vhost must look like the following::
|
|||
LogLevel warn
|
||||
CustomLog /var/log/httpd/logs.domain.tld-access.log combined
|
||||
|
||||
# Look out for the user/group which is different based on your distro
|
||||
WSGIDaemonProcess ara user=apache group=apache processes=4 threads=1
|
||||
|
||||
SetEnv ARA_WSGI_TMPDIR_MAX_AGE 3600
|
||||
SetEnv ARA_WSGI_LOG_ROOT /srv/static/logs
|
||||
SetEnv ARA_WSGI_DATABASE_DIRECTORY ara-report
|
||||
WSGIDaemonProcess ara user=apache group=apache processes=4 threads=1
|
||||
WSGIScriptAliasMatch ^.*/ara-report /var/www/cgi-bin/ara-wsgi-sqlite
|
||||
|
||||
<Directory "/usr/bin">
|
||||
<Files "ara-wsgi-sqlite">
|
||||
Require all granted
|
||||
</Files>
|
||||
</Directory>
|
||||
|
||||
# Redirect everything after /ara-report to the middleware
|
||||
WSGIScriptAliasMatch ^.*/ara-report /usr/bin/ara-wsgi-sqlite
|
||||
</VirtualHost>
|
||||
|
||||
You'll notice the ``WSGIScriptAliasMatch`` directive pointing to the WSGI
|
||||
script. This is bundled when installing ARA and can be copied to the location
|
||||
of your choice by doing::
|
||||
Using a virtual environment
|
||||
---------------------------
|
||||
|
||||
cp -p $(which ara-wsgi-sqlite) /var/www/cgi-bin/
|
||||
When using ARA from a virtual environment, you need to adjust your configuration
|
||||
accordingly.
|
||||
|
||||
For example, your vhost might need to look like this instead::
|
||||
|
||||
<VirtualHost *:80>
|
||||
# Remember that DocumentRoot and ARA_WSGI_LOG_ROOT must match
|
||||
DocumentRoot /srv/static/logs
|
||||
ServerName logs.domain.tld
|
||||
|
||||
ErrorLog /var/log/httpd/logs.domain.tld-error.log
|
||||
LogLevel warn
|
||||
CustomLog /var/log/httpd/logs.domain.tld-access.log combined
|
||||
|
||||
# Look out for the user/group which is different based on your distro
|
||||
WSGIDaemonProcess ara user=apache group=apache processes=4 threads=1 python-home=/opt/venv/ara
|
||||
|
||||
SetEnv ARA_WSGI_USE_VIRTUALENV 1
|
||||
SetEnv ARA_WSGI_VIRTUALENV_PATH /opt/venv/ara
|
||||
SetEnv ARA_WSGI_TMPDIR_MAX_AGE 3600
|
||||
SetEnv ARA_WSGI_LOG_ROOT /srv/static/logs
|
||||
SetEnv ARA_WSGI_DATABASE_DIRECTORY ara-report
|
||||
|
||||
<Directory "/opt/venv/ara/bin">
|
||||
<Files "ara-wsgi-sqlite">
|
||||
Require all granted
|
||||
</Files>
|
||||
</Directory>
|
||||
|
||||
# Redirect everything after /ara-report to the middleware
|
||||
WSGIScriptAliasMatch ^.*/ara-report /opt/venv/ara/bin/ara-wsgi-sqlite
|
||||
</VirtualHost>
|
||||
|
|
Loading…
Reference in New Issue