Does Tomcat 7 java.util.logging support sending logs to a remote syslog server?
It looks like log4j supports this:
log4j.appender.SYSLOG = org.apache.log4j.net.SyslogAppender
However, we are currently using RemoteIpValve so I'm not sure that will work under log4j.
server.xml
<Engine name="Catalina" defaultHost="localhost">
<Valve className="org.apache.catalina.valves.RemoteIpValve"
internalProxies="x.x.x.x" />
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="${LOG_DIR}/tomcat" prefix="access" suffix=".log"
pattern="combined" renameOnRotate="true" requestAttributesEnabled="true" />
Related
I have a tomcat server running perfectly fine apart from writing the access logs.
In Server.xml, the access log is defines like below:
<Server port="xxxx" shutdown="SHUTDOWN">
<GlobalNamingResources>
----
</GlobalNamingResources>
<Service name="Catalina">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="access." suffix=".log" pattern="common" resolveHosts="false"/>
<Connector --- />
<Connector --- />
<Executor --- />
<Engine name="Catalina" defaultHost="localhost">
<Realm ---/>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"></Host>
</Engine>
</Service>
I can see that accesslog valve is defined under service tag and not inside of Engine, host or Context as per common implementation. Can this be the reason behind the server not writing access logs
Official documentation suggesting supporting this: https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Access_Logs
Got this comment from server.xml :
A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
Every application deployed on my Tomcat returns status code 404 on every request I make. I've tried several projects, helloworlds or skeletons and every project behaves the same as others:
Some of the projects I've used:
https://github.com/mwarman/skeleton-ws-spring-boot
https://spring.io/guides/gs/rest-service/ (I can run it with mvn spring-boot:run but it's not working as deployed to Tomcat)
https://github.com/shagstrom/spring-mvc-hibernate-skeleton
I'm using the newest Tomcat8 (8.0.27), Oracle JDK 8. I've also tried Tomcat7 with OpenJDK 7.
Used Tomcats are running on MAC and Debian.
I've build apps via mvn and via Intellij Idea.
Tomcats are clean, no configs are changed (except adding manager-gui user).
Since I've tried many different projects, I don't believe the problem is in the code. Is it in Tomcat's config? How can I get it to work?
EDIT:
server.xml code:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<!-- 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
Note: The pattern used is equivalent to using pattern="common" -->
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
If you installed tomcat successfully, you may have seen tomcat main page from browser http://localhost:8080/ URL. (Otherwise, you need to check tomcat installation first.)
I guess you may have built jar by fallowing above sites that you mentioned.
I am wondering whether you applied the jar into your tomcat or not because you mentioned same result from any other projects.
You need to apply jar or war into your tomcat in order to apply java program.
Here are links that I wish they might be helpful to you.
Packaging war : How to make war file in Eclipse
Tomcat - war file deployment : https://www.youtube.com/watch?v=9X9DA8oVodk
If tomcat returns 404 response, you have to check those points:
check if your deploy was correct
check if war bootstrap and its ServletContext initialization has no errors
check if the resource your invoking was successfully exposed.
To test these issues you have to expose:
static resource test
web service resource test
in this way you can exclude the pitfalls you can meet during application deploy
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.
i need this kind of configuration:
Apache will respond to my blog if it is called on www.mydomain.com and i want to tomcat to respond to thirddomain.mydomain.com
I've configured a worker to respond to thirddomain.mydomain.com in this way:
<VirtualHost thirddomain.mydomain.com:80>
JkMount /* myworker
ServerName thirddomain.mydomain.com
</VirtualHost>
my worker is configured in this way:
worker.list=myworker
worker.myworker.port=8009
worker.myworker.host=thirddomain.mydomain.com
worker.myworker.type=ajp13
i've also a standard virtualhost that point to www
<VirtualHost www.mydomain.com:80>
DocumentRoot /var/www/html/blog/
ServerName www.mydomain.com
</VirtualHost>
the server.xml on tomcat is this one:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="thirddomain.mydomain.com">
<Host name="thirddomain.mydomain.com" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" resolveHost="false"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
The problem is that apache is responding on both www and mythirddomain. How i can configure it to respond on different third domains?
Thank you
First map "thirddomain.mydomain.com" (subdomain) to a valid directory, to check if that config works without ajp and Tomcat (comment out JKMount).
DocumentRoot /var/www/html/anotherDir/index.html
If that works uncomment JKMount and change this to use an ip:
worker.myworker.host=thirddomain.mydomain.com
should be:
worker.myworker.host=127.0.0.1
(I guess Tomcat is on the same server as your web server). Add the worker name in the Engine element as well:
<Engine jvmRoute="myworker" name="Catalina" defaultHost="thirddomain.mydomain.com">
I think you should use mod_proxy for this type of configuration. You can follow this link to learn more about mod_proxy module of apache. Apache Mod_Proxy.
Add the below two lines in your httpd.conf.
ProxyPass thirddomain.mydomain.com/ localhost:8080
ProxyPassReverse thirddomain.mydomain.com/ localhost:8080
Here your Apache HTTP Server will act as an reverse proxy.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I am trying to get Apache to forward requests to the examples that come with Tomcat. I did it once on another machine a few months ago, but on this new server I am stump.
Tomcat is running fine, localhost:8080 loads the default homepage and localhost:8080/examples/ displays the example page. But when I drop the 8080 and use port 80 on the apache server, it simply gives me a 404.
What is really bugging me is the lack of any log info on why. I am using the stock httpd-jk.conf with this added:
JkMount /examples/* worker1
Then this is my workers.properties:
worker.list=jk-status
worker.jk-status.type=status
worker.jk-status.read_only=true
worker.list=jk-manager
worker.jk-manager.type=status
worker.list=worker1
worker.worker1.reference=worker.template
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.activation=A
worker.template.type=ajp13
worker.template.socket_connect_timeout=5000
worker.template.socket_keepalive=true
worker.template.ping_mode=A
worker.template.ping_timeout=10000
worker.template.connection_pool_minsize=0
worker.template.connection_pool_timeout=600
worker.template.reply_timeout=300000
worker.template.recovery_options=3
And the Tomcat server.xml:
<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JasperListener" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
Answering with a checklist;
Are you certain port 80 is served by the Apache you expect - are your "404" responses showing in the access logs of that Apache instance
are you certain your mod_jk module is being loaded (see Apache logs, or use one of the Apache status page views to verify); if the module was not loaded, the JK configuration section would be silently ignored
are you certain your workers.properties is being found (Still, see Apache logs; you might also wish to raise the JkLogLevel in httpd.conf to trace for the time being; also, make sure you know where your JkLogFile is located)
Then about the SSL issue; mod_jk and mod_proxy_ajp should both work. If you just want basic "server-side SSL", and are not working with client certificates, then everything will be handled by your Apache httpd. If, on the other hand, you'll be doing client authentication using SSL client certificates, then I think there's another SO posting rather relevant to that use case.