Configuration to get the images from the apache - apache

I have multiple Tomcat servers. In each tomcat I am loading all images. I want to move the images from Tomcat to Apache and access the images from there.
My question is: is there any configuration to get the images in a Java web application from Apache instead of Tomcat?

I don't think so - images are shown by resolving their URL, and in most cases it is relative to the current page.
But you can use mod_proxy (or mod_jk) to use all your tomcats through Apache.

Hide your tomcat servers behind an apache server and then you can do something like this:
<VirtualHost www.example.com:80>
ServerName www.example.com
DocumentRoot /var/www/html
ProxyPass /img !
ProxyPass / ajp://localhost:1234/
</VirtualHost>
Apache will serve /img from /var/www/html/img and other requests will be sent to tomcat. This configuration needs mod_proxy_ajp apache module to be active. Tomcat must listen to AJP requests on the given port, use:
<Connector port="1234" protocol="AJP/1.3" redirectPort="8443" address="127.0.0.1" URIEncoding="UTF-8" />
And configure tomcat to serve www.example.com or the default virtual host.
<Host
name="www.example.com"
appBase="/path/to/tomcat/apps/www.example.com"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false"
/>
or
<Host
name="localhost"
appBase="/path/to/tomcat/apps/www.example.com"
unpackWARs="true"
autoDeploy="true"
xmlValidation="false"
xmlNamespaceAware="false"
/>
Deploy your webapp to /path/to/tomcat/apps/www.example.com/ as ROOT.war, this should be enough to have the whole setup up and running.

Related

How can I directly access my web application deployed in AWS tomcat using domain address?

I have deployed my Angular2 web application in AWS tomcat server which runs in 8080 port. I have my spring boot backend application deployed in the same tomcat server.
Already mapped my public address with my registered domain in Godaddy.
Now I can access my application appln by http://example.com:8080/my_client
I want to access it directly by http://example.com. dnt want to see 8080 port and appln name in the url.
Already tried with apache proxy config. However not able to get the expected one.
There are 2 options
1) change tomcat port from 8080 to 80 ( not recommended ).
nano tomcat_dir/conf/server.xml
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
2) use apache virtual host config.
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName example.com
ProxyPass http://example.com http://localhost:8080/example
ProxyPassReverse http://example.com http://localhost:8080/example
</VirtualHost>

Apache to tomcat proxy is not working

I have got apache 2.4, and 1 tomcat (connector port - 8081 and AJP - 8009) server (both on same linux box) on which I have an application folder named 'MyApp' in webapps directory.
Tomcat direct URL is - http://localhost:8081/MyApp/MyApp --> This links loads fine and displays the images, jquery and js works fine.
I am proxying all the requests to tomcat from apache using mod_proxy as mentioned below -
ProxyPass /MyApp ajp://localhost:8009/MyApp/MyApp
ProxyPassReverse /MyApp ajp://localhost:8009/MyApp/MyApp
Now, when I try to access it through web server URL, the URL loads but the images, css, jquery, which are inside the /u01/tomcat/webapps/MyApp directory doesnt work.
If I try to load the direct URL of the image, for example - http://localhost/MyApp/images/logo.jpg it doesnt work,
In the body of the image, I see -
HTTP Status 404 - /MyApp/MyApp/images/incidentReport.jpg
See above line, it is adding one more ''MyApp' to fetch the image
On the other hand, the tomcat URL [ localhost:8081/MyApp/images/logo.jpg ], loads fine.
What could be the issue? The developer of the application has designed it in such a way that it should work with a double 'MyApp' i.e. localhost:8081/MyApp/MyApp
What else do I need to do either on webserver/tomcat in order to make this work?
You need to follow these steps:
Step 1: Before configuring Apache, you should enable the necessary modules.
a2enmod proxy
a2enmod proxy_http
Step 2: Next, you are going to modify the default configuration file 000-default.conf inside /etc/apache2/sites-enabled to set up "proxying" functionality.
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8081/
ProxyPassReverse / http://0.0.0.0:8081/
ServerName localhost
</VirtualHost>
Step 3: Next, you are going to modify the server.xml file.
<Host name="www.drew-jocham.com" appbase="webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="resumesite_log." suffix=".txt"
pattern="common"/>
<Context path="" docBase="/MyApp/MyApp" debug="0" reloadable="true"/>
</Host>
Once you are done with your configuration, you will need to restart the cloud server for the changes to go into effect. Execute the following command to restart Apache: service apache2 restart
And that’s it!
Read more: https://medium.com/#ldclakmal/deploy-a-java-web-application-in-digitalocean-882226dcdbd5

Apache and Tomcat 8 configure proxy

I have a web application running in Tomcat 8. I can access this application by opening http://subdomain.domain.com:8080/MYAPP.
Now I want to only enter http://subdomain.domain.com to open this application.
How do I have to configure my Apache 2 or Tomcat 8 to achieve this?
See my answer there for more details.
https://stackoverflow.com/a/26305876/1935128
But basically, you need mod_proxy and maybe mod_proxy_connect enabled on apache with a proper virtualhost configuration on apache side. And on Tomcat's side it may work without any modification but you should add proxyName="subdomain.domain.com, proxyPort="80" and scheme="http"
Tomcat connector :
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"
<!-- This is the important part -->
proxyName="subdomain.domain.com" proxyPort="80"/>
Apache virtualhost:
<VirtualHost subdomain.mydomain.com:80>
ServerName http://subdomain.mydomain.com
# I think these two are optional, depending on the app your run on Tomcat
#ProxyRequests Off
#ProxyPreserveHost On
ProxyPass / http://your.tomcat.server:8080/MYAPP/
ProxyPassReverse / http://your.tomcat.server:8080/MYAPP/
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>

After using mod_proxy the web application is no more accessible from other computer

I used apache proxy support in tomcat to remove the port number from url. Here is what I did,
In http.conf file I added
LoadModule proxy_module mod_proxy.so
ProxyPass /alfresco http://localhost:8080/alfresco
ProxyPassReverse /alfresco http://localhost:8080/alfresco
In server.xml file of tomcat
<Connector port="8080" ...
proxyPort="80"/> (I didn't give proxy name)
Now I am able to access the web application using http:\\localhost/alfresco in my machine. But when I try this from other machine in my lan using http:\\machine1\alfresco I am getting page cannot be displayed error. But if I try http:\\machine1 I am getting It works page of apache. What went wrong?
Previously I am able to use the application from other machine.
I removed the proxy port="80" in server.xml file and now its working

TeamCity WebServer with Apache Proxy get "Method GET not implemented (try POST)"

I am trying setup TeamCity webserver on a server run Apache Proxy.
I added Add this to my Apache conf file
ProxyPass /TeamCity http://localhost/TeamCity
ProxyPassReverse /TeamCity http://localhost/TeamCity
And
added the Context to my TeamCity conf server.xml file in the Host section
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
docBase="C:\TeamCity\webapps\ROOT"
debug="1"
reloadable="true" > </Context>
Anyone know why I still get ""Method GET not implemented (try POST)"?
What is that actually mean?
I'm not sure how this is going to work.. It looks like you're trying to proxy http://your-server/TeamCity to http://localhost/TeamCity, unless your apache is on a different port..?
I've just implemented the a ProxyPass for my TeamCity install. My <Context> looks like:
<Host ...>
<Context path="/build" docBase="../webapps/ROOT"></Context>
</Host>
..Giving TeamCity the root URL of http://localhost:8111/build - See here for the apache doco on the tag. Without this, TC's Tomcat would redirect you to http://your-server/login.html instead of /build/login.html (results in a 404).
My httpd.conf contains (in the mod-proxy section):
ProxyPass /build http://localhost:8111/build
ProxyPassReverse /build http://localhost:8111/build
Which will proxy the requests and responses through /build to the new TeamCity URL. Works for me!