问题
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?
回答1:
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
来源:https://stackoverflow.com/questions/39977826/apache-to-tomcat-proxy-is-not-working