Switching from apache-tomcat-8.5.23 to apache-tomcat-8.5.50 configuring the ErrorReportValve is not working.
I have set below in 8.5.23 and it worked ( Tomcat does not show server info or error).
<Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false" />
After upgrade to 8.5.50 the tomcat shows server info and report, even I have set it to false
This is the sample stack trace and server info which is shown by Tomcat
Any comments?
You should set the configuration on the <Host> section in file server.xml.
<Host autoDeploy="false" appBase="webapps" name="localhost" unpackWARs="false">
<Valve className="org.apache.catalina.valves.ErrorReportValve" showReport="false" showServerInfo="false"/>
.
.
.
</Host>
Extracted from this reference.
I know this question might be similar to others, however, I haven't been able to solve this.
I have a server with 25 websites, all of them uses Tomcat. I'm migrating to a new server which has Tomcat 8 (the regular version), whereas the old server uses "CPanel's easy tomcat".
I started migrating one website, which is now running on the new server, however, when a JSP is called from the browser, the browser shows the JSP code instead of executing it.
In my old server, I had to execute a feature from CPanel's easy-tomcat called "install servlets", which I really don't know what it does, however, after executing that, Tomcat would execute JSP's.
Now, in my new server, accordgin to what I've read, I've added this to the %CATALINA_HOME%/conf/server.xml file, inside the <Engine></Engine> tags (which I also had to include in my old server):
<Host name="mydomain.com" appBase="/home/myAccName/public_html/">
<Context path="" reloadable="false" docBase="/home/myAccName/public_html" />
</Host>
As you can see, the application is not located under %CATALINA_HOME%/webapps/ directory, and that's the way I need it to be.
What am I missing?
Any help will be really appreciated
I'm using Tomcat 8, EasyApache 4 and CentOS 7.6
check that the following in in your tomcat/conf.web.xml file
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
You can create VirtualHosts to setup multiple websites with multiple domain names in one server. You can try out same in tomcat 7, 8 and in 9 as well.
1.Edit your relevant server.xml file and include Virtual hosts as below.
Make sure to restart your tomcat server for the applied changes to take effect.
<Host name="example.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.example.com</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="example_access_log" suffix=".txt"
pattern="%h %l %u %t %r %s %b" />
<Context path="" docBase="/opt/tomcat/webapps/myapp1"
debug="0" reloadable="true"/>
</Host>
<Host name="mydomain.org" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Alias>www.mydomain.org</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="mydomain_access_log" suffix=".txt"
pattern="%h %l %u %t %r %s %b" />
<Context path="" docBase="/opt/tomcat/webapps/myapp2"
debug="0" reloadable="true"/>
</Host>
Explanation
For example.com domain, /opt/tomcat/webapps/myapp1 is the document root (for your web 1).
For mydomain.org domain, /opt/tomcat/webapps/myapp2 is the document root(for your web 1).
This is the way I managed to solve this. I don't know if it's the best way, but it works. Just follow the next 3 steps:
1)
In %CATALINA_HOME%/conf/server.xml:
<Host name="mydomain.com" appBase="webapps" autoDeploy="false" unpackWARs="false"></Host>
2)
Then I had to add a file:
%CATALINA_HOME%/conf/mydomain.com/ROOT.xml
<Context displayName="My Website 1" docBase="/home/accountfolder/public_html" reloadable="true">
<Resource
name="jdbc/rhwebDB"
.
.
.
(database connection info, optional)
/>
</Context>
Then on the Apache side, I had to configure the mod_proxy_ajp connector
I've edited the file:
3)
/etc/apache2/conf.d/userdata/std/2/accountfolder/mydomain.com/cp_jkmount.conf
<IfModule mod_jk.c>
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
JkMount /servlets/* ajp13
</IfModule>
<IfModule mod_proxy_ajp.c>
ProxyRequests Off
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://mydomain.com:8009/
ProxyPassReverse / ajp://mydomain.com:8009/
My application/website is located on /home/accountfolder/public_html/ and there's nothing on the %CATALINA_HOME%/webapps/ directory. For me this is better since I can upload a jsp or whatever directly where the app is located using a FTP user.
If you have any trouble, check the folder permissions and owners in your /home/accountfolder/public_html/ directory, Tomcat needs permissions for reading/executing etc. A Tomcat's 404 error will be shown if Tomcat can't access those files & folders.
As I mentioned in this post, my app is "exploded" (if that's the correct term), I mean, it's NOT packed in a WAR file.
For example.com, the appBase for
a) www.example.com & example.com is /home/example/public_html/e - A wordpress site.
b) any other *.example.com is /home/example/public_html - A Java web app.
To achieve this, in server.xml, I am maintaining the following
a) For www & example.com
<Host name="example.com" appBase="/home/example/public_html/e" ...>
<Alias>www.example.com</Alias>
...
</Host>
b) For other wildcards, the following is NOT WORKING
<Host name="*.example.com" appBase="/home/example/public_html" ...>
...
</Host>
So, as a workaround, I have to MANUALLY ADD this whenever a,b,c etc are dynamically registered by the customers. Everytime requiring a Tomcat restart.
<Host name="*.example.com" appBase="/home/example/public_html" ...>
<Alias>a.example.com</Alias>
<Alias>b.example.com</Alias>
<Alias>c.example.com</Alias>
...
</Host>
MY QUESTION
Since the wildcards are dynamically generated at client registration, how do I dynamically set in server.xml such that the manual entry & Tomcat restart can be avoided.
The only way I know how at the moment is to specify the default host in server.xml
<Engine name="Catalina" defaultHost="default-host">
and then later on in the file you can specify all requests to go to a specific host
<Host name="example-site">
<Context path="" docBase="/home/example/public_html/e" />
<Alias>example.com</Alias>
<Alias>www.example.com</Alias>
</Host>
<Host name="registered-customers">
<Context path="" docBase="/home/example/public_html" />
<Alias>default-host</Alias>
</Host>
Good luck :)
I'm using Tomcat 7.I have my domain which pointed to qlhd.viweb.vn.Now I have some problem when I try to access my domain through internet. It always redirect to tomcat host manager page not my page. If I want to access my page I have to go through this http://qlhd.viweb.vn/CMS link.
I researched Google and add it to my server.xml
<Host name="www.qlhd.viweb.vn" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
</Host>
In my localhost I am using tomcat 8 which is having localhost_access_log file.In this file all the requests along with IPAddress,dateTime,Request type(get/post) along with full URL are captured.
But main server is not using tomcat 8 and they are using tomcat 6.So here there is no localhost_access_log file and hence I could not know what and when requests are made to server.
So is there any way to create localhost_access_log or any other way to know the requests made to server?
You have to change yout configuration to:
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
</Host>
See here for more information.