WSGIScriptAlias trailing slash issue

209 views
Skip to first unread message

Jason Garber

unread,
Oct 18, 2012, 3:41:31 PM10/18/12
to mod...@googlegroups.com
Hello,

I'm running into a strange problem where having a trailing slash on the end of a WSGIScriptAlias directive is causing me serious issues:

Using this version on Oracle Linux 6: 
   python32-mod_wsgi-3.4-1.ius.el6.x86_64

Note line 94.

 84 <VirtualHost 127.0.0.1:8123>
 86    DocumentRoot /home/jason/DevLevel.2/TCM/Web/MemberSite
 87    RewriteEngine on
 88    RewriteOptions inherit
 89    AddDefaultCharset UTF-8
 90    RewriteEngine on
 91    RewriteRule ^/m$  /mobile/  [R,L]
 92    RewriteRule \.(py|pyc|pyo|wsgi)$  -  [F]
 93    WSGIScriptAlias /api/callcenter/ /home/jason/DevLevel.2/TCM/Web/MemberSite/api/callcenter/index.wsgi
 94    WSGIScriptAlias /mobile  /home/jason/DevLevel.2/TCM/Web/MemberSite/mobile/index.wsgi
 95    WSGIScriptAlias / /home/jason/DevLevel.2/TCM/Web/MemberSite/index.wsgi
 96    WSGIProcessGroup Port8123
 97    LogLevel info
 98    ErrorLog /home/jason/DevLevel.2/TCM/apache-error.log
 99 </VirtualHost>


When requesting /mobile/login...

If it is "/mobile/", then I receive the following message in my apache error log:
[Thu Oct 18 15:31:14 2012] [error] [client 192.168.50.229] Target WSGI script not found or unable to stat: /home/jason/DevLevel.2/TCM/Web/MemberSite/mobile/index.wsgilogin

If it is "/mobile", then everything works fine.

The strange part here is at the end of the error message, we have "index.wsgilogin".  If I change the request to "/mobile/foobarbaz", then the error ends with "index.wsgifoobarbaz"

Is this a bug, or a feature?

Thanks!
Jason Garber








Jason Garber

unread,
Oct 18, 2012, 5:05:50 PM10/18/12
to mod...@googlegroups.com
It is worth noting that I have no issue with line 93, trailing slash included.

Noorul Islam Kamal Malmiyoda

unread,
Oct 19, 2012, 9:40:20 PM10/19/12
to mod...@googlegroups.com
Did you try ScriptAliasMatch ?

Thanks and Regards
Noorul

Jason Garber

unread,
Oct 19, 2012, 10:04:29 PM10/19/12
to mod...@googlegroups.com

No.  I do not need regex based matching, just prefix based.

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To view this discussion on the web visit https://groups.google.com/d/msg/modwsgi/-/A5s9ENXcvhEJ.
To post to this group, send email to mod...@googlegroups.com.
To unsubscribe from this group, send email to modwsgi+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en.

Graham Dumpleton

unread,
Oct 19, 2012, 10:35:56 PM10/19/12
to mod...@googlegroups.com
On 19 October 2012 06:41, Jason Garber <ja...@gahooa.com> wrote:
> 93 WSGIScriptAlias /api/callcenter/
> /home/jason/DevLevel.2/TCM/Web/MemberSite/api/callcenter/index.wsgi
> 94 WSGIScriptAlias /mobile
> /home/jason/DevLevel.2/TCM/Web/MemberSite/mobile/index.wsgi
>
> When requesting /mobile/login...
>
> If it is "/mobile/", then I receive the following message in my apache error
> log:
> [Thu Oct 18 15:31:14 2012] [error] [client 192.168.50.229] Target WSGI
> script not found or unable to stat:
> /home/jason/DevLevel.2/TCM/Web/MemberSite/mobile/index.wsgilogin
>
> If it is "/mobile", then everything works fine.
>
> The strange part here is at the end of the error message, we have
> "index.wsgilogin". If I change the request to "/mobile/foobarbaz", then the
> error ends with "index.wsgifoobarbaz"
>
> Is this a bug, or a feature?

I would not expect any problem with /mobile/login.

I actually would expect the problem you are describing with
/api/callcenter/login however.

When using WSGIScriptAlias and the target is a file, you should never
use a trailing slash on the mount point.

The only time a trailing slash should be use on mount point is if
mounting at root of site, ie., '/', or the target is actually a
directory and not a file. In this latter case, the target directory
path should also have a trailing slash.

You sure you were playing with trailing slash on the /mobile one?

Graham

Jason Garber

unread,
Oct 20, 2012, 12:30:52 AM10/20/12
to mod...@googlegroups.com

Hey Graham,

I've typically mounted with trailing slash with no issues.

Can you point out why it would sometimes work, or maybe a deeper understanding of how WSGIScriptAlias actually works in apache.  If you have time, or a link.

Thanks - this is something i'd like to have a better handle on.

J

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.

Graham Dumpleton

unread,
Oct 21, 2012, 12:49:16 AM10/21/12
to mod...@googlegroups.com
You could get away with a trailing slash for a sub URL for mount
point, where target is exact path for a WSGI script file, where the
requested URL is exactly the mount point and with no trailing path
info.

Thus you can have:

WSGIScriptAlias /suburl/ /some/directory/file.wsgi

but this will only work for the URL /suburl/.

If you use /suburl/path then it will fail with a 404 in the browser and error:

Target WSGI script not found or unable to stat: /some/directory/file.wsgipath

in the Apache error log.

You end up with this as Apache removes the mount point from the URL
and puts that on the end of the target path, because it strips the '/'
at end of mount point, when joining the path it gets mucked up.

If you really need a trailing slash on the mount point, then you could
technically use:

WSGIScriptAlias /suburl/ /some/directory/file.wsgi/

In short the rule is that for a sub URL, if there is a trailing slash
on one, there must be on the other. You cannot have it on one and not
the other.

Mount point at top of site, ie.. '/', is treated in a special way by
mod_wsgi to avoid this requirement. If mod_wsgi hadn't treated it
specially, you would need to use:

WSGIScriptAlias / /some/directory/file.wsgi/

in much the same way you have to with ScriptAlias. I personally found
that looked really silly and it gave lots of problems in FASTCGI
solutions where people left it off, so I made the special allowance to
make trailing slash on target WSGI script file optional for mount
point of '/'.

Graham

Jason Garber

unread,
Oct 22, 2012, 1:47:06 PM10/22/12
to mod...@googlegroups.com
Hey Graham,

Okay, so now that I read your email below, and went back and read the docs, it all makes perfect sense.  May I suggest you copy and paste this email below as a "Notes" (eg, a grey box) in the documentation under that section?  I think it is very clear and adds to the docs you already have.

Thanks,
Jason
Reply all
Reply to author
Forward
0 new messages