Raghuram
Raghuram

Reputation: 52625

Tomcat and proxy request

I configure a default tomcat installation (running on "localhost" at port "8080") as a proxy server in my browser and try to connect to http://www.google.com.

I would expect either an error message saying tomcat is not configured as a proxy server or I should get the contents of google website.

Instead I get the index.html page of my tomcat installation.

What is going wrong?

Upvotes: 0

Views: 2926

Answers (3)

sosiouxme
sosiouxme

Reputation: 1256

Tomcat doesn't know that it's supposed to proxy the request. All it knows is that your browser showed up and asked it for something, like this:

GET http://www.google.com/example HTTP/1.1
[plus other headers]

With Apache HTTPD, you might have configuration such that when a request shows up for a host that's not itself, it acts as a proxy for the request.

Tomcat is not generally used as a proxy. Tomcat is however frequently used behind a reverse proxy where the request may be for something like "www.google.com" which may be relayed back to Tomcat as the site it's supposed to be serving. Tomcat's standard configuration pretty much accepts the host specified as its own, and adopts it for the purpose of creating absolute references to itself, with the assumption that if a request got to it, it was legitimate. You can of course alter this behavior with configuration, but if you don't, Tomcat is pretty much going to try to serve what you requested from its set of applications, assuming you knew what you were doing with the Host header.

Upvotes: 2

ZZ Coder
ZZ Coder

Reputation: 75456

Tomcat doesn't have any built-in proxy function. I don't know what configuration you are talking about.

The browser will request an URI like "http://google.com/examples". If the Tomcat is configured with a default host and default welcome page, it will be displayed. It doesn't understand the proxy request at all.

You have to install a proxy servlet and map it to the root to use Tomcat as a proxy server.

Upvotes: 0

davogones
davogones

Reputation: 7399

All a proxy server does is pass requests and responses through. From your browser's perspective, you requested a URL, the proxy server returned HTML and a code 200, so this is interpreted as the response from the requested URL. Since this is a static page and not a real proxy server, all requests will result in the same static response.

Upvotes: 0

Related Questions