You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by André Warnier <aw...@ice-sa.com> on 2011/06/01 01:31:40 UTC
Re: specifying the content-type
Lentes, Bernd wrote:
> Hi,
>
> first, i'm new to tomcat and i'm not a java developer.
You have all my sympathy.
> My collegues developed a web application i have to deploy now. I'm using tomcat6 on a sles 11 sp1 box.
> I configured a httpd (apache 2.2.10) in front of the tomcat, which communicates with tomcat using AJP.
> When i open one link, i don't see the desired web page, but the source code of it. Using tcpdump shows me that the content type in the http-header is text/plain.
That is typical of a bad/dangerous configuration of Apache, mod_jk and Tomcat.
You are probably
a) allowing Apache to "see" the contents of the Tomcat webapps directory directly
(e.g. by setting the Apache DocumentRoot = the Tomcat webapps dir.)
b) not properly indicating to Apache/mod_jk that these URLs must be proxied to Tomcat via
mod_jk (JkMount instructions).
As a consequence, when you request from Apache a URL like (for example)
"/myapp/something.jsp", Apache goes directly to that file and serves it back to the
browser. Of course since Apache does not know what a .jsp file is, it treats it as plaint
text and that is what it says in the Content-type header.
Do the following test to confirm the above :
request the URL "/myapp/WEB-INF/web.xml"
(where "myapp" is the first part of the URL for a Tomcat application).
If you see the content of the web.xml file in the browser, then the above is probably
true, because Tomcat would never show the content of that file (or anything else in a
WEB-INF directory).
(The reason why I mention above that it is "dangerous", is that by doing that you also
allow Apache to completely go around whatever access security would be configured in Tomcat.)
> Ok, that's the reason why i see the source code.
Yes
> Can i configure the content-type which is delivered by tomcat ?
You can, but you should not have to, because it is not the problem here.
Tomcat never receives the request for that file; it is Apache only which reads that file
and sends it back. So changing something in Tomcat won't help.
> I tried using mod_mime_magic on httpd,
but this module just helps specifying the content-type of static files. Our content is
dynamic.
Yes, and that is like putting new paint on top of schimmel.
You should fix the configuration first.
If you want further help, give us an idea of the layout on disk of your Apache and Tomcat
directories, and of the URLs that should be processed by Tomcat.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: specifying the content-type
Posted by "Lentes, Bernd" <be...@helmholtz-muenchen.de>.
Pid wrote:
>
> On 01/06/2011 10:55, Lentes, Bernd wrote:
> > lrwxrwxrwx 1 root root 20 Apr 18 16:33 webapps ->
> /srv/tomcat6/webapps/
>
> What is in the webapps dir? A directory called 'mouseidgenes'?
>
Yes.
> If so, what is the file tree in that directory?
>
vm53200-12:~ # l /srv/tomcat6/webapps/mouseidgenes
total 268
drwxr-xr-x 6 tomcat tomcat 4096 May 30 16:55 ./
drwxrwxr-x 8 root tomcat 4096 May 30 16:55 ../
-rw-r--r-- 1 tomcat tomcat 1481 May 20 15:02 Applet.htm
-rw-r--r-- 1 tomcat tomcat 2443 May 9 16:21 Download.html
drwxr-xr-x 2 tomcat tomcat 4096 May 30 16:55 File_Ressources/
-rw-r--r-- 1 tomcat tomcat 2798 May 23 14:35 IDGenesStyle.css
-rw-r--r-- 1 tomcat tomcat 6088 Apr 13 10:40 LinkedSelection.js
drwxr-xr-x 2 tomcat tomcat 4096 May 30 16:55 META-INF/
-rw-r--r-- 1 tomcat tomcat 498 Apr 13 11:53 MailingList.html
drwxr-xr-x 4 tomcat tomcat 4096 May 30 17:03 WEB-INF/
drwxr-xr-x 6 tomcat tomcat 4096 May 30 16:55 classes/
-rw-r--r-- 1 tomcat tomcat 2032 Apr 13 11:54 contact.html
-rw-r--r-- 1 tomcat tomcat 7239 May 9 16:13 help.html
-rw-r--r-- 1 tomcat tomcat 2500 Apr 13 11:55 home.html
-rw-r--r-- 1 tomcat tomcat 443 May 11 13:16 ind2_old.html
-rw-r--r-- 1 tomcat tomcat 378 May 20 15:59 ind_old.html
-rw-r--r-- 1 tomcat tomcat 434 Apr 29 22:31 intSearch_old.html
-rw-r--r-- 1 tomcat tomcat 85925 May 11 09:40 jquery.min.js
-rw-r--r-- 1 tomcat tomcat 37133 Apr 20 12:47 jquery.validate.js
-rw-r--r-- 1 tomcat tomcat 4731 May 4 14:14 main_new.htm
-rw-r--r-- 1 tomcat tomcat 1409 May 20 14:47 menu.htm
-rw-r--r-- 1 tomcat tomcat 1930 Mar 25 10:22 terminAuswahl.js
-rw-r--r-- 1 tomcat tomcat 14537 May 4 09:44 tidy.html
-rw-r--r-- 1 tomcat tomcat 28948 May 9 13:55 xhtml2fo.xsl
> What is "/mouseidgenes/InputData"? Is it a servlet or a JSP?
It's a servlet.
Extract from web.xml:
...
<servlet>
<servlet-name>InputData</servlet-name>
<servlet-class>input.InputData</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>InputData</servlet-name>
<url-pattern>/InputData</url-pattern>
</servlet-mapping>
...
Bernd
Helmholtz Zentrum München
Deutsches Forschungszentrum für Gesundheit und Umwelt (GmbH)
Ingolstädter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir´in Bärbel Brumme-Bothe
Geschäftsführer: Prof. Dr. Günther Wess und Dr. Nikolaus Blum
Registergericht: Amtsgericht München HRB 6466
USt-IdNr: DE 129521671
Re: specifying the content-type
Posted by Pid <pi...@pidster.com>.
On 01/06/2011 10:55, Lentes, Bernd wrote:
> lrwxrwxrwx 1 root root 20 Apr 18 16:33 webapps -> /srv/tomcat6/webapps/
What is in the webapps dir? A directory called 'mouseidgenes'?
If so, what is the file tree in that directory?
What is "/mouseidgenes/InputData"? Is it a servlet or a JSP?
p
RE: specifying the content-type
Posted by "Lentes, Bernd" <be...@helmholtz-muenchen.de>.
Andre Warnier wrote:
> Lentes, Bernd wrote:
> > Hi,
> >
> > first, i'm new to tomcat and i'm not a java developer.
>
> You have all my sympathy.
>
> > My collegues developed a web application i have to deploy
> now. I'm using tomcat6 on a sles 11 sp1 box.
> > I configured a httpd (apache 2.2.10) in front of the
> tomcat, which communicates with tomcat using AJP.
> > When i open one link, i don't see the desired web page, but
> the source code of it. Using tcpdump shows me that the
> content type in the http-header is text/plain.
>
> That is typical of a bad/dangerous configuration of Apache,
> mod_jk and Tomcat.
> You are probably
> a) allowing Apache to "see" the contents of the Tomcat
> webapps directory directly (e.g. by setting the Apache
> DocumentRoot = the Tomcat webapps dir.)
No.
webapps=/srv/tomcat6/webapps
DocumentRoot=/srv/www/htdocs
> b) not properly indicating to Apache/mod_jk that these URLs
> must be proxied to Tomcat via mod_jk (JkMount instructions).
>
mod_jk.conf:
...
JkMount /mouseidgenes/* appl01
...
> As a consequence, when you request from Apache a URL like
> (for example) "/myapp/something.jsp", Apache goes directly to
> that file and serves it back to the browser. Of course since
> Apache does not know what a .jsp file is, it treats it as
> plaint text and that is what it says in the Content-type header.
>
>
> Do the following test to confirm the above :
> request the URL "/myapp/WEB-INF/web.xml"
> (where "myapp" is the first part of the URL for a Tomcat application).
HTTP Error 404.
>
> > Can i configure the content-type which is delivered by tomcat ?
>
> You can, but you should not have to, because it is not the
> problem here.
> Tomcat never receives the request for that file;
It does receive the request. I log all the AJP stuff, and you see there, among others:
This is the request from the client:
...
[Tue May 31 20:51:46 2011] [24717:4165998336] [debug] init_ws_service::mod_jk.c (888): Service protocol=HTTP/1.1 method=GET host=(null) addr=146.107.135.80 n
ame=vm53200-12 port=80 auth=(null) user=(null) laddr=146.107.35.101 raddr=146.107.135.80 uri=/mouseidgenes/InputData
...
The reponse:
...
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_unmarshal_response::jk_ajp_common.c (608): status = 200
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_unmarshal_response::jk_ajp_common.c (615): Number of headers is = 0
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1117): received from ajp13 pos=0 len=8188 max=8192
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1117): 0000 03 1F F8 3C 48 65 61 64 3E 3C 74 69 74
6C 65 3E - ...<Head><title>
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1117): 0010 4D 6F 75 73 65 49 44 47 65 6E 65 73 3C
2F 74 69 - MouseIDGenes</ti
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1117): 0020 74 6C 65 3E 3C 2F 68 65 61 64 3E 0A 0D
0A 3C 73 - tle></head>...<s
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1117): 0030 63 72 69 70 74 20 74 79 70 65 3D 27 74
65 78 74 - cript.type='text
[Tue May 31 20:51:48 2011] [24717:4165998336] [debug] ajp_connection_tcp_get_message::jk_ajp_common.c (1117): 0040 2F 6A 61 76 61 73 63 72 69 70 74 27 20
73 72 63 - /javascript'.src
...
> If you want further help, give us an idea of the layout on
> disk of your Apache and Tomcat directories, and of the URLs
> that should be processed by Tomcat.
>
OK:
vm53200-12:/etc/apache2 # l /usr/share/tomcat6/
total 12
drwxr-xr-x 3 root root 4096 Apr 18 16:33 ./
drwxr-xr-x 200 root root 4096 May 30 08:00 ../
drwxr-xr-x 2 root root 4096 Apr 18 16:33 bin/
lrwxrwxrwx 1 root root 12 Apr 18 16:33 conf -> /etc/tomcat6/
lrwxrwxrwx 1 root root 15 Apr 18 16:33 lib -> ../java/tomcat6/
lrwxrwxrwx 1 root root 16 Apr 18 16:33 logs -> /var/log/tomcat6/
lrwxrwxrwx 1 root root 23 Apr 18 16:33 temp -> /var/cache/tomcat6/temp/
lrwxrwxrwx 1 root root 20 Apr 18 16:33 webapps -> /srv/tomcat6/webapps/
lrwxrwxrwx 1 root root 18 Apr 18 16:33 work -> /var/cache/tomcat6/
vm53200-12:/etc/apache2 # l /srv/www/
total 16
drwxr-xr-x 4 root root 4096 Apr 17 17:46 ./
drwxr-xr-x 5 root root 4096 Apr 18 16:33 ../
drwxr-xr-x 2 root root 4096 Apr 17 17:49 cgi-bin/
drwxr-xr-x 3 root root 4096 May 23 18:08 htdocs/
URL that should be processed:
http://vm53200-12/mouseidgenes/InputData
(talking to httpd in front of tomcat, result is source code in the browser)
http://vm53200-12:8080/mouseidgenes/InputData
(talking directly to tomcat coyote, result is a correctly displayed web page).
Bernd
Helmholtz Zentrum München
Deutsches Forschungszentrum für Gesundheit und Umwelt (GmbH)
Ingolstädter Landstr. 1
85764 Neuherberg
www.helmholtz-muenchen.de
Aufsichtsratsvorsitzende: MinDir´in Bärbel Brumme-Bothe
Geschäftsführer: Prof. Dr. Günther Wess und Dr. Nikolaus Blum
Registergericht: Amtsgericht München HRB 6466
USt-IdNr: DE 129521671