URL redirection from Apache to Tomcat using mod_jk - mod-jk

My apache document root is /srv/www/htdocs/ and my url is https://internal.net/
My requirement is to open a URL https://internal.net/jenkins-project/ which should have document root as /usr/share/tomcat7/webapps/jenkins-project/ rather than looking into /srv/www/htdocs/jenkins-project/
I tried using mod_jk and have configured a worker property with name worker1 and am using it in httpd.conf as mentioned below
JkMount /jenkins-project/* worker1
But still throwing an error
File does not exist: /srv/www/htdocs/jenkins-project/

I have used below code in tomcat's server.xml and restarted Tomcat. Its working fine now.
<Context path="/jenkins-project" docBase="jenkins-project" debug="0" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="jenkins-project" suffix=".log" timestamp="false"/>
</Context>

Related

Impossible to display static images saved on tomcat server in a jsp after trying all context docBase configurations

Im unable to display an image uploaded by a user on my local server (D:\fichiers)in a JSP,
using pure Jee (no spring), Tomcat 9, intelli-j idea.
I've tried everything i could find :
I tried to add :
<Context docBase="D:\fichiers" path="/images"/>
in context.xml in meta-inf, in server.xml in Tomcat installation conf folder, in server.xml in Tomcat/conf of the app, in catalina/localhost/root.xml, in catalina/localhost/context.xml.
But i still get an error 404, images not found.
Here is the server.xml file :
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Context docBase="D:\\fichiers" path="/images"/>
<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 the jsp call :
<c:set var="chemin">/images/</c:set>
<c:forEach items="${spot.photos}" var="photo">
<img src="${chemin}${photo.nom}"/>
</c:forEach>
The only time it worked is when i checked on tomcat configuration
Deploy applications configured in Tomcat instance
But i had to remove it, cause Catalina was starting springframework on its own, and nothing worked properly after that.
Ok i found the answer, and though it's stupidly simple, i couldn't find a place where it was said.
In Tomcat configuration tab in Intelli-j :
Deployment Tab -> Add external Source -> Select the local Drive -> Put URL desired in Application Context, and that's it !

The username you provided is not allowed to use the text-based Tomcat Manager (error 403) when deploying on remote Tomcat8 using Jenkins

I am trying to deploy a WAR on the remote Tomcat (Remote Machine) using Jenkins deploy to container Plugin.
I have done the following configuration in tomcat-users.xml
<user username="deployer" password="deployer" roles="manager-gui,manager-script,admin" />
I have setup the proper username password and port in Jenkins deployer container plugin. The setup is working fine for the local Tomcat.
But for remote Tomcat I keep getting the following error:
Caused by: org.codehaus.cargo.container.tomcat.internal.TomcatManagerException: The username you provided is not allowed to use the text-based Tomcat Manager (error 403) at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:555)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:686)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:699)
at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:174)
... 16 more
Caused by: java.io.IOException: Server returned HTTP response code: 403 for URL: http://1.203.190.5:8080/manager/text/list
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:544) ... 19 more
This seems to be a Jenkins bug but I got around the problem by setting up following configuration in Tomcat:
Edit the file /webapps/manager/META-INF/context.xml:
Previous:
<Context antiResourceLocking="false" privileged="true">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
</Context>
Change this file to comment the Value:
<Context antiResourceLocking="false" privileged="true">
<!--
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>
This resolved the issue.
I was facing the same issue while deploying artifact to tomcat with jenkins via container plugin,
Solution:- i have added manager-script and manager-gui in the roles of the user and provide the full access to webapps/* directory. It helps me to deploy the artifact successfully and able to view it with manager-app.
My OS : Debain 10
I solved this by editing file /opt/tomcat/conf/tomcat-users.xml and added manager-script role
<role rolename="admin-gui,manager-gui,manager-script,manager-jmx,manager-status,admin-gui"/>
<user username="admin" password="password" roles="admin-gui,manager-gui,manager-script"/>
You just need to add the jenkins IP address to the valve.
You need to update : /webapps/manager/META-INF/context.xml. Because it allows only localhost. If you know the specific hostname or IP, you can add it replacing XXX.XXX.XXX.XXX by the IP address.
It's realy important to keep the security in place.
<Context antiResourceLocking="false" privileged="true" >
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|XXX.XXX.XXX.XXX" />
</Context>
After that, you need to restart tomcat.
$CATALINA_HOME/bin/shutdown.sh && $CATALINA_HOME/bin/startup.sh
If nothing works simply create another user in tomcat-users.xml file with magnager-script role assigned and set this user credential to jenkins .
In tomcat-users.xml file
<tomcat-users>
<user username="deployuser" password="deployuser" roles="manager-script" />
<user username="admin" password="admin" roles="manager-gui" />
</tomcat-users>
In Tomcat 9, you don't need to add any manager-XXX roles. All you have to do is add the users and and assign the manager-gui (for GUI access) and manager-script (for access like Jenkins deployment ).
Also, make sure to edit the file /webapps/manager/META-INF/context.xml, either to comment out valve or define appropriate reg ex for allow attribute
Step 1:
We need to update : \webapps\manager\META-INF\context.xml. Bcs it allows only localhost. If you know the specific hostname or IP, you can add.
<Context antiResourceLocking="false" privileged="true" >
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
-->
</Context>
Step 2:
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="tomcat" roles="manager-gui, manager-script"/>
Deployment went successful.
I had the same issue. Changing the username to "admin" should do the work.

Accessing Tomcat manager throws 404

I am using Tomcat 7.0.65.
Here is my tomcat-users.xml:
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-status"/>
<user username="admin" password="tomcat" roles="manager,manager-gui,manager-script,manager-status"/>
Here is the server realm snippet in server.xml
<Realm className="org.apache.catalina.realm.MemoryRealm" />
I can access the below urls : [It asks for the credentials for the first time]
http://localhost:8080/manager/status
http://localhost:8080/manager/status/all
But accessing any of the urls :
http://localhost:8080/manager/text/sessions?path=/examples
http://localhost:8080/manager/text/serverinfo
fails with "404 Not found". Below is the displayed error message:
The page you tried to access (/manager/text/sessions) does not exist.
The Manager application has been re-structured for Tomcat 7 onwards and some of URLs have changed. All URLs used to access the Manager application should now start with one of the following options:
/manager/html for the HTML GUI
/manager/text for the text interface
/manager/jmxproxy for the JMX proxy
/manager/status for the status pages
Note that the URL for the text interface has changed from "/manager" to "/manager/text".
You probably need to adjust the URL you are using to access the Manager application. However, there is always a chance you have found a bug in the Manager application. If you are sure you have found a bug, and that the bug has not already been reported, please report it to the Apache Tomcat team.
Note that I am accessing the url as /manager/text . Even curl fails with the same error.
Am I missing any configuration?
After much debugging, I found the real cause was the ManagerServlet was failing to get instantiated with the below security exception:
java.lang.SecurityException: Restricted (ContainerServlet) class org.apache.catalina.manager.ManagerServlet
The way to fix is to set "privileged=true" in the "Context" section in TOMCAT_INSTALL_DIR/conf/context.xml
<!-- The contents of this file will be loaded for each web application -->
<Context privileged="true">
<!-- Default set of monitored resources. If one of these changes, the -->
<!-- web application will be reloaded.
Provide the roles below in the conf/tomcat-users.xml file.
<user username="test" password="test" roles="admin-gui,manager-gui"/>

RAP application with entrypoint path defined to "/" is not working on Tomcat7

My RAP application has entrypoint defined following
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.rap.ui.entrypoint">
<entrypoint
brandingId="com.ibm.kc.redirect.validator.rap.branding"
class="com.ibm.kc.redirect.validator.rap.app.ApplicationWorkbench"
id="entrypoint"
path="/">
</entrypoint>
</extension>
...
It works fine with IBM WAS Liberty but not on Tomcat7. Tomcat's context root is same as name of war in webapps. So when I access localhost:8080/kc-redirect-tester it should work.I defined entry point to "/" means servlet path after context root is only "/". I see lot of 404 where RWT resources going to localhost:8080/, like they had no idea of tomcat's context root.
In tomcat7, http://127.0.0.1:8080/{appname}/
The appname must be the name of the war (eg. appname.war) and not the value of in your web.xml servlet definition file. then add the context "/", => http://127.0.0.1:8080/{appname}/ (don't forget the last "/")

jetty load multiple context

We have an maven+springMVC application that uses maven jetty plugin to start the app up when we do development. We use a jetty-env.xml file to set a context and JNDI config. The application will be part of a bigger portal.
We are using maven jetty plugin
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>7.2.0.v20101020</version>
with config
<webAppConfig>
<contextPath>/ASX/mainApp</contextPath>
<jettyEnvXml>src/main/resources/jetty-env.xml</jettyEnvXml>
</webAppConfig>
and use jetty-env.xml
<Configure id='jms-webapp-wac' class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/ASX/mainApp</Set>
...
...
</Configure>
Our dir structure is:
MainApp
/forms
page1.html
page2.html
etc...
/WEB-INF
web.xml
PortalApp
/BAL_S
/css
/images
/js
etc...
Now the PortalApp only has static files and is not really a web application i.e. it doesn't have web.xml
The application is dependent on javaScripts from the portal. The location of some of the javaScript are like:
<script src="/BAL_S/js/portal-jquery-lib.js"></script>
<script src="/BAL_S/js/libs/foundation.js"></script>
etc...
As you can see that the location starts with /BAL_S which we are finding tricky to get working as it's like referring to another webapp context. When we start the application with jetty we get javaScript errors because it cannot find /BAL_S
If we deploy our app in tomcat and configure it, as below, the application works fine without any javaScript errors.
<Context path="/" docBase="PortalApp"/>
So the question is how can I do the similar configuration in Jetty so when the application starts up it detects /BAL_S context?
I guess we need to have two contexts in Jetty. How do I configure that?
What is the webConfig for maven jetty plugin to refer to this config?
Hope someone can help. Example would be useful.
Thanks in advance.
GM
OK All I had to do was add to maven jetty plugin configuration, the following:
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.webapp.WebAppContext">
<contextPath>/</contextPath>
<resourceBase>src/main/PortalApp/</resourceBase>
</contextHandler>
</contextHandlers>
So this configures context path '/' to 'src/main/PortalApp/' and now we are able to get to /BAL_S in the tag.

Resources