Bypass web2py for static maintenance page

33 views
Skip to first unread message

Ian W. Scott

unread,
Sep 19, 2022, 6:07:18 PMSep 19
to web2py-users
I'm trying to set up a static maintenance page under apache that doesn't depend on web2py. The problem is that the mod_wsgi scriptalias directive seems to override the rewrite instructions to serve the static maintenance page.

My apache config includes this:

  ErrorDocument 503 /maintenance/maintenance.html
  RewriteEngine on
  RewriteCond /var/www/html/maintenance/maintenance.enabled -f
  RewriteCond %{REQUEST_URI} !=/maintenance/maintenance.html
  RewriteRule ^ - [R=503,L]

This works fine as long as I disable the mod_wsgi scriptalias directive:

WSGIScriptAlias / /path/to/my/web2py/wsgihandler.py

Basically I need web2py to handle any urls from the base of my domain. Except I want to bypass that alias for paths beginning "/maintenance".

Any suggestions for how to configure this?

Thanks,

Ian

Ian W. Scott

unread,
Sep 21, 2022, 5:26:47 PMSep 21
to web2py-users
I found the answer to my own question. So in case anyone else finds it useful:

Instead of using the WSGIScriptAlias directive you can use WSGIScriptAliasMatch which allows for regular expressions. Then I used a negative lookahead to exclude any paths beginning with "maintenance":

WSGIScriptAliasMatch "^/(?!maintenance).*$" /path/to/my/web2py/wsgihandler.py

It works like a charm. Now when I activate maintenance mode apache serves the static html page in /var/www/html/maintenance. Otherwise, it redirects all other requests to the wsgi handler for web2py.

Dave S

unread,
Sep 30, 2022, 3:36:51 AMSep 30
to web2py-users
On Wednesday, September 21, 2022 at 2:26:47 PM UTC-7 scot...@gmail.com wrote:
I found the answer to my own question. So in case anyone else finds it useful:

Instead of using the WSGIScriptAlias directive you can use WSGIScriptAliasMatch which allows for regular expressions. Then I used a negative lookahead to exclude any paths beginning with "maintenance":

WSGIScriptAliasMatch "^/(?!maintenance).*$" /path/to/my/web2py/wsgihandler.py

It works like a charm. Now when I activate maintenance mode apache serves the static html page in /var/www/html/maintenance. Otherwise, it redirects all other requests to the wsgi handler for web2py.



Thanks for sharing this.

/dps
Reply all
Reply to author
Forward
0 new messages