Since you tried gunicorn and your other sub sites do it, why not use Apache as a proxy to mod_wsgi-express?
Use of mod_wsgi-express was already mentioned in that video you linked. You can find some blog posts specifically about the topic of using it behind Apache as a proxy at: http://blog.dscpl.com.au/2015/06/proxying-to-python-web-application.html <http://blog.dscpl.com.au/2015/06/proxying-to-python-web-application.html> http://blog.dscpl.com.au/2015/07/redirection-problems-when-proxying-to.html <http://blog.dscpl.com.au/2015/07/redirection-problems-when-proxying-to.html> Just ignore that it talks about the mod_wsgi-express running in docker as that doesn't need to be the case. Finally, since part of the issue seems to relate to the mount point of the application, mod_wsgi-express does have a --mount-point option so that you can when it is behind the proxy still have it mounted as a sub path to make things potentially easier. If you are concerned about performance, your application is robust and you don't need the protections that daemon mode of mod_wsgi-express offers for auto recovery (which you aren't using in your current manual Apache setup with daemon mode), you can set the backend mod_wsgi-express to use embedded mode using --embedded-mode. This will eliminate some of the extra latency of using a proxy to backend Apache to daemon mode. Using mod_wsgi-express means that also not subject to using the older mod_wsgi version that RHEL ships with as installing it from PyPi instead. So as first step perhaps get your application working under mod_wsgi-express and see if it works and ask questions about anything you aren't quite sure about or can't get working. Also see: http://blog.dscpl.com.au/2015/04/using-modwsgi-express-with-django.html <http://blog.dscpl.com.au/2015/04/using-modwsgi-express-with-django.html> http://blog.dscpl.com.au/2015/04/integrating-modwsgi-express-as-django.html <http://blog.dscpl.com.au/2015/04/integrating-modwsgi-express-as-django.html> Graham > On 14 Aug 2021, at 2:40 am, Matt J <[email protected]> wrote: > > Hello All, > > Firstly let me say that I have done my best over the past couple weeks to > find a solution to this problem, but have come up with no concrete solutions, > mostly because of limitations in my corporate environment. I've found many > helpful resources such as this one > https://www.youtube.com/watch?v=H6Q3l11fjU0, but am coming straight to the > source for this question. > > How can I change the log location of mod_wsgi output (the app output) without > defining my app under a separate virtual host? > > I am hosting a Django Application using Python 3.7.10 on a RHEL7 server using > Apache version 2.4 and mod_wsgi version 4.8.0. This server uses only a single > virtual host to host multiple corporate applications (java, perl, python > etc), and this server hosts them typically using proxies and locations under > the single virtual host server01.corp.com:443. Because domain name is > important and cannot be changed due to "its the way we have always done > things", my django app must be hosted at server01.corp.com and aliased to a > script path /apps/djangosite. Therefore, a conf.d for the site looks like > this: > ----------------------------------------------------------------- > <Location "/apps/djangosite "> > #How all other apps are hosted on server01.corp.com using a proxy > #ProxyPass "http://127.0.0.1:9889" retry=0 > #ProxyPassReverse "http://127.0.0.1:9889" > <IF "req('Authorization') =~ /^Bearer/"> > #stuff > </IF> > <ELSE> > #stuff but with ldap > </ELSE> > > Require valid-user > # Forward the REMOTE_USER env var as a request header > RequestHeader set X-Remote-User %{REMOTE_USER}s > RequestHeader set X-Remote-Host %{REMOTE_HOST}s > > #Add some variables for Django > #RequestHeader set X-Script-Name /apps/djangosite/ > #RequestHeader set X-Forwarded-Script-Name /apps/djangosite/ > </Location> > > #mod_wsgi Specific Entries > <Directory /fullpath/mysite/static> > Options FollowSymLinks Includes > Require all granted > </Directory> > > Alias /apps/djangosite/static/ /fullpath/mysite/static/ > > <Directory /fullpath/mysite> > <Files wsgi.py> > Require all granted > </Files> > </Directory> > > WSGIDaemonProcess djangosite-api processes=2 threads=15 > python-home=/fullpath/envs/djangosite_api/ user=corpuser > home=/fullpath/djangosite python-path=/fullpath:/fullpath:/fullpath > WSGIProcessGroup djangosite-api > WSGIScriptAlias /apps/djangosite /fullpath/mysite/wsgi.py > process-group=compute-api > WSGIRestrictEmbedded On > WSGIApplicationGroup %{GLOBAL} > > #pull mod_wsgi out of ssl_error_log > SetEnvIf Request_URI ^/apps/djangosite(/.*|$) djangosite-api > CustomLog /fullpath/logs/djangosite.debug.log combined env=djangosite-api > LogLevel debug wsgi:Trace8 > ----------------------------------------------------------------- > > Logging Directives in settings.py > LOGGING = { > 'version': 1, > 'disable_existing_loggers': False, > 'formatters': { > 'verbose': { > 'format': '{levelname} {asctime} {module} {process:d} {thread:d} > {message}', > 'style': '{', > }, > }, > 'handlers': { > 'file': { > 'level': 'DEBUG', > #'class':'logging.StreamHandler' > 'class': 'logging.FileHandler', > 'filename': ' /fullpath/logs/djangosite.debug.log ' > } > }, > 'root': { > 'handlers': ['file'], > 'level': 'DEBUG', > }, > 'loggers': { > 'django': { > 'handlers': ['file'], > 'level': 'INFO', > 'propagate': True, > } > } > } > > And so here is the problem: With over 10 other deployed apps on > server01.corp.com, the ssl_error_log of this one virtual host is pretty quick > to bury messages, and I want to be able to get my apps log in a specific > location, rather then sifting through the hosts log. If I was able to create > another host, this wouldnt be an issue obviously. I can get django debug info > from the logging directive, and some very slight request logging from setting > the custom log above, but I will never be able to get stack traces or wsgi > startup info unless I go to the ssl_error_log. I have read the warnings on a > portable application using stderr/stdout, and have tried to make the > application as portable as the development environment will allow. I cannot > find a way to change the log location of a specific module in apache. I tried > gunicorn as a alternative to mod_wsgi, but mod_wsgi has a cleaner setup for > us and apache/gunicorn struggled to host djangosite on anything other than > the root /. > > Is there any way to circumvent this inability to create another virtualhost > while still having full control of logging? > > Thank you for your time, > Matt J > > > -- > You received this message because you are subscribed to the Google Groups > "modwsgi" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/modwsgi/fc14abce-0f43-4e35-a91e-05310847947an%40googlegroups.com > > <https://groups.google.com/d/msgid/modwsgi/fc14abce-0f43-4e35-a91e-05310847947an%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "modwsgi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/376A608B-3450-4303-A496-634CFDC9DB0E%40gmail.com.
