Web2py/Apache accessible via multiple host names

153 views
Skip to first unread message

Michael Suelmann

unread,
Oct 2, 2015, 5:06:26 PM10/2/15
to web2py-users
Hello,

I'm running web2py 2.12.3-stable on Fedora 22 with apache-2.4.16, python-2.7.10 and use the following config lines for WSGI:
WSGIDaemonProcess default display-name=%{GROUP}
WSGIProcessGroup default
WSGIScriptAlias /welcome /var/wsgi/web2py/wsgihandler.py/welcome
WSGIScriptAlias /examples /var/wsgi/web2py/wsgihandler.py/examples
...

The server is reachable via multiple host names, like example.com and www.example.com. All should show the same content, so I use just one <VirtualHost _default_:443> in the apache config.

If I restart apache and go to https://
example.com/welcome all is fine. If I go to https://www.example.com/welcome after that I get the following error:

Traceback (most recent call last):
File "/var/wsgi/web2py/gluon/main.py", line 436, in wsgibase
session.connect(request, response)
File "/var/wsgi/web2py/gluon/globals.py", line 960, in connect
session_pickled = pickle.dumps(self, pickle.HIGHEST_PROTOCOL)
File "/var/wsgi/web2py/gluon/storage.py", line 56, in <lambda>
__getnewargs__ = lambda self: getattr(dict,self).__getnewargs__(self)
TypeError: getattr(): attribute name must be string

After restarting apache again I can access https://www.example.com/welcome fine but https://example.com/welcome will then cause the error. This happens with all web2py apps.

What can I do to get this to work except of redirecting all host names to one version?

Greetings
Michael


Niphlod

unread,
Oct 2, 2015, 6:45:50 PM10/2/15
to web2py-users
remove the double wsgiscriptalias.
Or trade apache for nginx + uwsgi. Less headaches for everybody.

Michael Suelmann

unread,
Oct 3, 2015, 11:08:30 AM10/3/15
to web2py-users
Hello Niphlod,

The double WSGIScriptAlias is because the web2py apps aren't the only thing served by apache, so I can't just alias everything to wsgihandler.py. Actualy there are some more WSGIScriptAlias as there are more web2py apps on the server.
Anyway, I did a test with just the following WSGIScriptAlias:
WSGIScriptAlias / /var/wsgi/web2py/wsgihandler.py
And the result was the same.

Greetings
Michael

Niphlod

unread,
Oct 5, 2015, 6:19:13 AM10/5/15
to web2py-users
but you can't pass a directory to it no matter what. 

Michael Suelmann

unread,
Oct 5, 2015, 1:09:45 PM10/5/15
to web2py-users
Hello Niphlod,

The directive "WSGIScriptAlias /welcome /var/wsgi/web2py/wsgihandler.py/welcome" actually does work. At least if I stay with one host name for accessing the web server all my web2py apps work fine. And as I tested if I change it to "WSGIScriptAlias / /var/wsgi/web2py/wsgihandler.py" all web2py apps continue to work (just the other stuff doesn't wok anymore), but my original problem stays the same:

If I access the pages with a different server name in the URL than the first access I get the stated error.

Greetings
Michael

Niphlod

unread,
Oct 5, 2015, 3:43:11 PM10/5/15
to web2py-users
ok, I'll rephrase, a bit harshly... why are you insisting on passing something completely undocumented to wsgiscriptalias ? If there's a good reason, you should be able to sort it out, or at least explain clearly the reason behind it. 
Sadly, "it works for the first request" isn't really "it works".
Web2py is dropping apache "primary" support because of tons of those nonsensical setups weirdness. You insisting on a totally different config from the mainstream isn't helping. Without a solid reason, you'll probably end revisiting your config by yourself, just because you're the only one willing to do so.
Those errors are easy to research on google and are not tied to web2py setups: it seems a general issue with apache.
If you don't want "to run uwsgi and be happy" as suggested, at least give the people trying to help the benefit of the doubt, then maybe, but just maybe, bash them around insisting on a better config EXPLAINING why it's better (and working): they'll happily take your input and spread your wisdom thoughout all the plagued community restricted to run apache.
For the time being, please consider the above suggestion PLUS restricting every single entry-point to your web2py sites with a solid copy of the same configuration AND a WSGIDaemonProcess with a different name for every entry. That seems to seal the deal for any apache+wsgi installation.

Michael Suelmann

unread,
Oct 5, 2015, 4:46:41 PM10/5/15
to web2py-users
Hello Niphlod,

sorry, I didn't want to bash you. And I'm not saying my config is better. It's just that my apache is serving some other stuff additionally on the same VirtualHost and if I use a WSGIScriptAlias for / I either have to alias everything else or the other part won't work. I wonder where I got my use of WSGIScriptAlias, must have been documented somewhere. And for using nginx + uwsgi: Apache has been working fine (except for web2py) and getting all other stuff converted to a different webserver would take quite some time.

As for "it works": The behavior for the web2py apps is the same regardless if I use my undocumented way for WSGIScriptAlias or not. I mostly got them running as I've changed all URLs I found to access the server by only one name and then all was fine. The problem is that some users still have bookmarks or there are links somewhere for an older name for the server so that I can't prevent access with another name without stranding users.

Actually you gave me the clue I needed with your last reply regarding "WSGIDaemonProcess with a different name for every entry". I now created several VirtualHost entries and set up a WSGIDaemonProcess with a different name for each (I had to duplicate quite some part of my configuration). And now it works!

Thanks for your help.

(I did search for my error message but didn't find anything that pointed into that direction. And when I read you can't share WSGIDaemonProcesses between VirtualHost entries some time ago I though I'm not affected because I only had one VirtualHost entry.)

Greetings
Michael

o

unread,
Jan 2, 2016, 8:12:31 AM1/2/16
to web2py-users
Hi,
It might be relevant:
https://groups.google.com/d/topic/web2py/cZTV9YRqWGk
https://groups.google.com/forum/#!topic/web2py/mmOWQfOUw98

Yet what Massimo suggested about updating routes_in and routes_out did not work for me
(in Apache 2.4 + mod_wsgi / web2py-2.13.4-stable on kubuntu 14.04)
when I used routes.patterns.example.py as a template for routes.py and set
BASE = 'w2p' there. The routing went completely wrong way.

The supplied with web2py routes.parametric.example.py suggested another solution that I ended up with
to allow independent php and python applications on the same apache2:

1. cp <path-to-web2py>/examples/routes.parametric.example.py <path-to-web2py>/routes.py

2. appending path_prefix='w2p', to the BASE router there:

routers = dict(
    # base router
    BASE=dict(
        default_application='welcome',
        path_prefix='app',
    ),
)

3. updating VirtualHost config with

WSGIScriptAlias /w2p <path-to-web2py>/wsgihandler.py
...
AliasMatch ^/w2p/([^/]+)/static/(?:_[\d]+.[\d]+.[\d]+/)?(.*) <path-to-web2py>/applications/$1/static/$2
...
<Location /w2p/admin>
  Require ip 127.0.0.1
</Location>
...
<LocationMatch ^/w2p/([^/]+)/appadmin>
  Require ip 127.0.0.1
</Location>
...
that seems to work for 'user applications', but some links generated in the admin app still appear to ignore path_prefix and land on the webroot.
When I append webroot in the resulting urls with '/w2p' manually in the browser location box they sometimes work.

Good luck,
o
Reply all
Reply to author
Forward
0 new messages