Friday, January 21, 2011

Apache ProxyPass not serving php properly

I've configured Apache to proxy all requests to foo.bar.com except for the the alias /bazbar. The proxy portion of the configuration works and the proxy pass portion works except that it serves the index.php as a plain text file.

How can I get Apache to serve the php files properly? Here is my configuration.

<VirtualHost *:80>
  ServerName foo.bar.com
  Alias /bazbar /var/www/bazbar

  ProxyPreserveHost On

  ProxyPass /bazbar !

  <Location /bazbar>
    SetHandler None
  </Location>

  <Location />
    Order allow,deny
    allow from all
    ProxyPass http://localhost:8080
    ProxyPassReverse http://localhost:8080
  </Location>
</VirtualHost>

*note I have confired that php is configured properly because when I go to http://localhost/somescript.php the php renders properly

  • If you visit http://localhost:8080/ on that machine, do you get index.php served as a text file or does it run on the server? In the case of proxy, apache will simply take what it got, and feed it back to the client. My first look would be there.

    adam : http://localhost:8080 is a separate application. When I go to http://localhost/bazbar/index.php the php script is rendered properly. The problem is that http://foo.bar.com/bazbar/index.php serves index.php as plain text. Does that help clarify?
    Richard June : I misunderstood. I follow you now. Then I think the section is your problem, If you read this page: http://httpd.apache.org/docs/1.3/mod/mod_mime.html#sethandler You'll notice that you're disabling all handlers for that Location. If you remove the SetHandler directive, I think you'll find that it works.
    adam : That was it. I replaced SetHandler None with Order allow,deny and allow from all and that worked. Can you submit another answer with that suggestion so I can accept that answer? I want to make sure the answer I accept is clear for others who read this question.
  • Look at the <Location /bazbar> section. SetHandler None disables all handlers for that Location. You need to remove that directive in order for it to work as you expect.

0 comments:

Post a Comment