0

The .htaccess :

AddHandler wsgi-script .wsgi
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.wsgi/$1 [QSA,L,PT]

The index.wsgi :

import atexit
import threading
import cherrypy

cherrypy.config.update({'environment': 'embedded'})

if cherrypy.engine.state == 0:
        cherrypy.engine.start(blocking=False)
        atexit.register(cherrypy.engine.stop)

class Root:
        def index(self):
            return "..."
            index.exposed = True

    def default(self):
            return "default"
                index.exposed = True

application = cherrypy.tree.mount(Root(), "/")
  • It is a shared host, i don't have access to apache
  • I'm not allowed to use WSGIScriptAlias

The 404 error comes from cherrypy(powered by cherrypy on the botton), so i conclude apache is calling the .wsgi file correctly, it seems that its also passing /index.wsgi/, and cherrypy does not know what to do with it.

Can anyone help me with this?

I never deployed a cherrypy app before, is this the best/only/recommended way to do it?

Thanks in advance.

OldJim
  • 301
  • 2
  • 5

1 Answers1

1

If setting RewriteBase to '/' in .htaccess, likely that you need to use:

RewriteRule ^(.*)$ /index.wsgi$1 [QSA,L,PT]
Graham Dumpleton
  • 6,090
  • 2
  • 21
  • 19
  • Thank you for taking the time to answer, still Cherrypy outputs : 404 - The path '/index.wsgi' was not found. Any ideas? – OldJim Aug 25 '10 at 16:50
  • See 'http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive'. You need to use a WSGI wrapper script to fiddle SCRIPT_NAME when you are using the rewrite rule method. Didn't catch you weren't doing this before. If that recipe has a problem now with missing slash, you may need to put it back in rewrite rule or otherwise will need to fiddle with it a bit to get it to work as example is not for .htaccess file. – Graham Dumpleton Aug 25 '10 at 23:20
  • That was it, i had to set SCRIPT_NAME to "", that solved, tnx for the help, Jim. – OldJim Aug 26 '10 at 01:20
  • Did you still need to drop the '/' out of the RewriteRule, or were both changes required? – Graham Dumpleton Aug 26 '10 at 03:29
  • It worked with the .htaccess as it is in the post, the only change i made was setting environ["SCRIPT_NAME"] = "", my database connections died though (http://tools.cherrypy.org/wiki/Storm) apparently mod_wsgi handles threads differently, do you happen to know if there's another event where i could hook the connection?Tnx in advance. – OldJim Aug 26 '10 at 04:50
  • The mod_wsgi package doesn't do any thing out of the ordinary with threads. A Python application should see them the same as if run under pure Python WSGI server. Do however read 'http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading'. If you are running multithread configuration and the software you are using is not thread safe you will have issues. You could also be having issues with multiprocess configuration. – Graham Dumpleton Aug 27 '10 at 03:31