Multiple virtualhosts for two python sites, one dominates

Question:

I’m trying to get an apache server configured on a Mac server to serve both a Web2Py app and a Flask application. This has become a mild nightmare. I would like the users to be able to go to the following urls

http:/my.domain.com/ – Web2py site

http:/my.domain.com/suburl – Flask site

Unfortunately, when I visit the suburl, it always takes me to the Web2py site (which then freaks out because there’s no application named suburl). Here is my .conf file:

NameVirtualHost *:80
# Flask Site
<VirtualHost *:80>
   ServerName my.domain.com/suburl
   WSGIDaemonProcess flask-suburl user=_www group=_www
   WSGIProcessGroup flask-suburl
   WSGIScriptAlias /suburl /Users/myname/suburl/app.wsgi
   <Directory /Users/myname/suburl>
      WSGIApplicationGroup %{GLOBAL}
      Order deny,allow
      Allow from all
   </Directory>
</VirtualHost>

# Web2py Site
<VirtualHost *:80>
   ServerName my.domain.com
   WSGIDaemonProcess web2py-main user=_www group=_www
   WSGIProcessGroup web2py-main
   WSGIScriptAlias / /Users/myname/web2py/wsgihandler.py
   <Directory /Users/myname/web2py>
      AllowOverride None
      Order Allow,Deny
      Deny from all
      <Files wsgihandler.py>
         Allow from all
      </Files>
   </Directory>
</VirtualHost>

Reordering the two VirtualHost definitions doesn’t do anything. Removing the Web2py site allows me to access the Flask site.

I’d rather not combine them into a single VirtualHost, because that causes problems with the two applications sharing the same Python interpreter and certain C extensions are apparently flipping out.

I’ve changed the domain and a few other names to hide protected information. I’m also excluding a few AliasMatch commands that handle serving the static subfolders. There’s also another VirtualHost for the SSH server on port 443, but I didn’t include it because I expect that to not affect things.

So how on earth do I make it so I can visit both sites, instead of the Web2py site swallowing everything?

Asked By: Austin Cory Bart

||

Answers:

For anyone coming here, I’ve solved my problem. It was a simple mistake, and I could have sworn I had tried this before.

In the configuration for the Flask site, I should have done:

ServerName my.domain.com
...
WSGIScriptAlias /suburl /Users/myname/suburl/app.wsgi

Notice that the ServerName no longer has /suburl at the end of it. Instead, make sure that that has been added to the first argument of WSGIScriptAlias. The reasoning becomes clear when you look at the documentation for WSGIScriptAlias; the first argument is the URL-path that is being accessed. ServerName must remain pure.

Answered By: Austin Cory Bart
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.