How to remove jsessionid from URL in my local Tomcat7 in Eclipse - java

I have a java web app that I deploy in production with Tomcat7.
I use the Tomcat Web Application Manager page in production, where I deploy my WAR at the context path "/". In production I'm not seeing jsessionid in URL.
In my development environment though, the same application (hence the same web.xml), started with Tomcat7 inside eclipse is showing jsessionid in URL.
The only session configuration I have in my web.xml is:
<session-config>
<session-timeout>15</session-timeout>
</session-config>
The only difference I can see in both Tomcat7 is the server.xml:
Production:
<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>
Local:
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context docBase="MyApp" path="/" reloadable="true" source="org.eclipse.jst.jee.server:MyApp" />
</Host>
Another difference is that I use NGinx in production to do a proxy pass from port 80 to 8080 from Tomcat.
What may I be missing?
Thanks

You may using a browser or other client that doesn't support (or disabled) cookies in your development environment.
Another Tip: you may use this code in tomcat 7 (in your web.xml file):
<session-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>

The problem is that for cookies to work properly, the domain name must have at least two dots (https://curl.haxx.se/rfc/cookie_spec.html).
So to make it work locally, I had to do the following:
Change the /etc/hosts file to include any domain name with at least one period, pointing to 127.0.0.1:
127.0.0.1 localhost
127.0.0.1 localhost.test
255.255.255.255 broadcasthost
::1 localhost
Change the context.xml to include the new domain:
<Context sessionCookieDomain=".localhost.test" sessionCookiePath="/">
...
</Context>

Related

Setup Tomcat for multiple websites in one server (linux)

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.

Java App not loading on tomcat 9 centos 7

I'm pretty new to linux and I've been thrown into it. So far I made it work a few times, but this time it got me bad. The aim is to cluster tomcat and load balance with nginx but the app error is taking too much time from me. The app is correctly deployed by tomcat but is not accesible through browser. I've checked permissions, dns resolution, ports. The app resides out of webapps folder.
Java 8 installed from yum
Tomcat 9 taken with wget
Configured tomcat service to autostart
Added execution permits to .sh's
I honestly dont know what I'm missing. The same app currently runs under centos 6 on production server.
Thanks in advance
Finally I got it working. I was missing the <Context.../> just beneath my <Host.../> declaration. Production server doesn't have that line, so I supposed there was no need for it. Nevertheless the first time I got it working, I don't remeber having that set up.
Like this:
</Realm>
<Host name="hostname" appBase="/app/base/" unpackWARs="true" autoDeploy="false">
<Context path="" docBase="/app/base/" reloadable="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>

How to create sub-domains in Apache Tomcat 8

I have installed Apache tomcat 8 on my windows server 2012 where I need to store my Java applications. I have 3 apps: app1, app2, app3
Right now if I put into my - Tomcat 8.0\webapps folder war file called ROOT.war app starts on address mydomain.com and works fine - but I need to be able to run several apps at the same tomcat - Thats's why I want to create subdomains
app1 should launch on app1.mydomain.com
app2 should launch on app2.mydomain.com
app3 should launch on app3.mydomain.com
How can I fulfill this?
I search similar topics here on stack-overflow but nothing helped.
Please help.
Actually I solved my issue like this:
I have configured server.xml file located in my case in Program Files (x86)\Apache Software Foundation\Tomcat 8.0\conf folder
found there this code:
<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>
made a copy of it and replaced the values with my subdomains:
<Host name="app1.mydomain.com " appBase="app1.mydomain.com "
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>
and that's it actually.
For myself I also removed default localhost HOST and now I have only subdomains.

how to create localhost_access_log file in tomcat 6

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.

Apache + Tomcat

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.

Categories

Resources