views:

87

answers:

2

I am trying to run CherryPy behind Apache using mod_rewrite, as described in the CherryPy documentation (BehindApache, ModRewrite), and it is not working.

Edit: Earlier, my description of this problem was somewhat inaccurate. It seems like I forgot to restart Apache during some of my attempts. I have revised the question significantly.

When I run my program (a very simple "hello world" program similar to the first tutorial file that comes with CherryPy), it seems to work fine. If I run curl "http://127.0.0.1:8080" from my server, I can see the output, and I see some sort of record of it in the CherryPy log.

However, if I try to access the site from my browser, I get a 403 Forbidden error saying "You don't have permission to access / on this server.". I do not see any record of it in the CherryPy log. I tried putting the RewriteRule (RewriteRule ^(.*) http://127.0.0.1:8080$1 [proxy]) in the appropriate VirtualHost section of my httpd.conf file, both with and without the slash, and both times I got the same error. In my Apache error log, I see lines like this:

[Mon Sep 27 15:54:11 2010] [error] [client 123.45.67.89] attempt to make remote request from mod_rewrite without proxy enabled: proxy:http://127.0.0.1:8080/

I tried putting the RewriteRule in the .htaccess file of my site instead, and I got 404 Not Found errors, with lines like this in my error log:

[Mon Sep 27 13:31:54 2010] [error] [client 123.45.67.89] Attempt to serve directory: proxy:http://127.0.0.1:8080/

I still didn't see any entries in the CherryPy log.

I decided to see what would happen if I tried to access the site without CherryPy running, and I got the same thing. It is as if Apache is trying unsuccessfully to communicate with the CherryPy program if I put the line in httpd.conf, and completely unaware of it when I put the line in .htaccess.

Does anyone here know why this is happening, and what to do about it? I have tried everything I could think of. My site is running on a DreamHost private server with Debian 4.3.2-1.1, Apache 2.2.15, Python 2.6.5, and CherryPy 3.1.2.

Edit 2: lazy1, I tried your suggestion and it did not help. I am getting the same 403 errors.

A: 

You might want to try and bind cherrypy to 0.0.0.0 (all interfaces)

    cherrypy.config.update({"server.socket_host" : "0.0.0.0"})
lazy1
+2  A: 

I run CherryPy behind Apache in a very similar way. Apache serves static content itself, and any URLs starting with 'cp' are servied by CherryPy. CherryPy is listening on port 8500. Here's what works for me in httpd.conf:

RewriteMap escape int:escape
  [...]
RewriteRule ^/cp\/(.*) http://localhost:8500/cp/${escape:$1} [L,P]

This is inside the VirtualHost definition (well, the RewriteMap line is outside it, but you get the picture)

Obviously you have to make sure mod_proxy is getting loaded. Check the RewriteRule documentation as well.

In my CherryPy config, I have:

server.socket_host = "127.0.0.1"
server.socket_port = 8500

Good luck!

Bill Gribble
I tried enabling mod_proxy, and then whenever I try to access anything on my site's domain, I get a 500 error. I don't know why this is happening. Nothing at all gets added the error log. I tried your suggestion anyway and it didn't work.
mikez302
Are there any specific options I need to set in mod_proxy for it to work properly? I am not very familiar with it.
mikez302
Be sure you have both mod_proxy and mod_proxy_http; see the mod_proxy docs for more:
Bill Gribble
Oops, content: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxy
Bill Gribble
I tried also enabling mod_proxy_http and it seems to work! Thank you. If I don't run into any major problems related to this issue before the end of the bounty period, I will award the bounty to you.
mikez302