WSGI, Apache2, and web2py NOT at root

175 views
Skip to first unread message

Mark Larsen

unread,
Apr 14, 2009, 10:27:25 AM4/14/09
to web...@googlegroups.com
I'm struggling setting up web2py with Apache2 and mod_wsgi. I've
followed the manual, (page 205) mainly-->

Alias / /home/web2py/applications/
## setup WSGI
WSGIScriptAlias / /home/web2py/wsgihandler.py
WSGIDaemonProcess web2py user=www-data group=www-data
home=/home/web2py/ 12 processes=10 maximum-requests=500

But this installs web2py at the root of the server. You can of course do:

WSGIScriptAlias /web2py /home/web2py/wsgihandlder.py

But then all your URL() calls on longer work, since they become
http://server/controller/function.

Anyone struggled with this before?

Mark

Yarko Tymciurak

unread,
Apr 14, 2009, 12:36:57 PM4/14/09
to web...@googlegroups.com
you may need to set other things... (servername?)


provides any hints for you....

Mark Larsen

unread,
Apr 15, 2009, 12:30:04 PM4/15/09
to web...@googlegroups.com
> See if http://forum.webfaction.com/viewtopic.php?pid=8473#p8473
> provides any hints for you....

Thanks Yarko.

It still has the troublesome line:

WSGIScriptAlias / /home/[YOUR ACCOUNT]/webapps/apachewsgi/web2py/wsgihandler.py

Which essentially tells apache to handle anything coming at the root
of the server through the wsgihandler.py

I did figure out a hack if anyone comes up against this problem:

RewriteEngine on
RewriteRule ^/[NAMEOFAPP](.*)$ /web2py/[NAMEOFAPP]$1 [PT,L]
WSGIScriptAlias /web2py /opt/web2py/wsgihandler.py

This essentially allows you to place web2py outside of root.
Mod_Rewrite then rewrites the URLs to fix what would be broken URLs so
when URL() function writes:

http://server/nameofapp/

it becomes:

http://server/web2py/nameofapp

The PT (pass-through) directive ensures the users does not see the rewriten URL.

Thanks,

Mark

Johann Spies

unread,
Feb 13, 2010, 2:47:15 PM2/13/10
to web...@googlegroups.com
On 15 April 2009 18:30, Mark Larsen <lars...@gmail.com> wrote:
>
> I did figure out a hack if anyone comes up against this problem:
>
> RewriteEngine on
> RewriteRule ^/[NAMEOFAPP](.*)$ /web2py/[NAMEOFAPP]$1 [PT,L]
> WSGIScriptAlias /web2py /opt/web2py/wsgihandler.py
>
> This essentially allows you to place web2py outside of root.
> Mod_Rewrite then rewrites the URLs to fix what would be broken URLs so
> when URL() function writes:

I am trying to set up web2py alongside a php-site behind apache and
came across this thread. I have tried to modify the configuration
file created by Massimo's Ubuntu setup script using the above hint of
a RewriteRule but it works only partially:

I get the index page without the layout and css and no subsequent pages.

I would appreciate some help to get this working.

In the log I get:
[Sat Feb 13 21:34:30 2010] [error] [client 196.36.153.134] File does
not exist: /var/www/sadec
[Sat Feb 13 21:34:42 2010] [error] [client 196.36.153.134] File does
not exist: /var/www/sadec, referer:
http://kbase.sun.ac.za/web2py/sadec

The web2py stuff is in /home/www-data/web2py.

My configuration:

NameVirtualHost *:443
WSGIDaemonProcess web2py user=www-data group=www-data
WSGIProcessGroup web2py


RewriteEngine on
RewriteRule ^/[NAMEOFAPP](.*)$ /web2py/[NAMEOFAPP]$1 [PT,L]

WSGIScriptAlias /web2py /home/www-data/web2py/wsgihandler.py

<VirtualHost *:80>


<Directory /home/www-data/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>

AliasMatch ^/([^/]+)/static/(.*) \
/home/www-data/web2py/applications/$1/static/$2
<Directory /home/www-data/web2py/applications/*/static/>
Order Allow,Deny
Allow from all
</Directory>

<Location /admin>
Deny from all
</Location>

<LocationMatch ^/([^/]+)/appadmin>
Deny from all
</LocationMatch>

CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>

<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/self_signed.cert
SSLCertificateKeyFile /etc/apache2/ssl/self_signed.key

WSGIProcessGroup web2py

WSGIScriptAlias /web2py /home/www-data/web2py/wsgihandler.py

<Directory /home/www-data/web2py>
AllowOverride None
Order Allow,Deny
Deny from all
<Files wsgihandler.py>
Allow from all
</Files>
</Directory>

AliasMatch ^/([^/]+)/static/(.*) \
/home/www-data/web2py/applications/$1/static/$2

<Directory /home/www-data/web2py/applications/*/static/>
Order Allow,Deny
Allow from all
</Directory>

CustomLog /var/log/apache2/access.log common
ErrorLog /var/log/apache2/error.log
</VirtualHost>


Regards
Johann

rppowell

unread,
Feb 13, 2010, 6:02:32 PM2/13/10
to web2py-users
I don't know if this would help, but I had this problem in setting up
web2py using FastCGI:

I wanted to have web2py in a subdirectory off of my main page;
http://www.rppowell.com/web2py/
Here is what I put in my .htaccess:
RewriteEngine On
RewriteRule ^dispatch\.fcgi/ - [L]
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

(this is similar to the WSGIScriptAlias configuration)

I had to then fix the URLs generated by web2py to put in the '/
web2py/' directory.
I rename routes.example.py (in web2py directory) to routes.py and
edit:

routes_out=(('/(?P<a>.*)','/web2py/\g<a>'),)

-rppowell

Christopher Steel

unread,
Feb 15, 2010, 10:31:02 AM2/15/10
to web2py-users
This is a "reprint" from web2pyslice located here ->
http://www.web2pyslices.com/main/slices/take_slice/29 and a comment I
left. Some of the other comments look like they could be helpful as
well, I notice at least one about an updated ubuntu install script.
Here is my comment regarding the Ubuntu Apache setup:

I got errors with that setup but when I tried changing the following
it worked with no Apache errors:

VirtualHost *:80>
WSGIDaemonProcess web2py user=www-data group=www-data display-name=%
{GROUP}

To be this:

VirtualHost *:80>
WSGIDaemonProcess web2py user=www-data group=www-data

lets Apache run with no error...

On Feb 13, 2:47 pm, Johann Spies <johann.sp...@gmail.com> wrote:

mdipierro

unread,
Feb 15, 2010, 11:10:56 AM2/15/10
to web2py-users
I am changing this in trunk. I run into the same problem. The new
script also prompts you for the admin password.

On Feb 15, 9:31 am, Christopher Steel <chris.st...@gmail.com> wrote:
> This is a "reprint" from web2pyslice located here ->http://www.web2pyslices.com/main/slices/take_slice/29and a comment I

Christopher Steel

unread,
Feb 16, 2010, 7:42:18 AM2/16/10
to web2py-users
Thanks,

In our new documentation scheme would this become a comment in the now
online book?

C

On Feb 15, 11:10 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> I am changing this in trunk. I run into the same problem. The new
> script also prompts you for the admin password.
>
> On Feb 15, 9:31 am, Christopher Steel <chris.st...@gmail.com> wrote:
>

> > This is a "reprint" from web2pyslice located here ->http://www.web2pyslices.com/main/slices/take_slice/29anda comment I

mdipierro

unread,
Feb 16, 2010, 9:45:51 AM2/16/10
to web2py-users
No. This should got in the errata page (to be created and attached to
preface) until it is fixed in the book.

On Feb 16, 6:42 am, Christopher Steel <chris.st...@gmail.com> wrote:
> Thanks,
>
> In our new documentation scheme would this become a comment in the now
> online book?
>
> C
>
> On Feb 15, 11:10 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > I am changing this in trunk. I run into the same problem. The new
> > script also prompts you for the admin password.
>
> > On Feb 15, 9:31 am, Christopher Steel <chris.st...@gmail.com> wrote:
>

> > > This is a "reprint" from web2pyslice located here ->http://www.web2pyslices.com/main/slices/take_slice/29andacomment I

Reply all
Reply to author
Forward
0 new messages