Apache2 proxy reverse broken Tomcat8 links - apache

In my DigitalOcean vps, I have Apache2 (LAMP), phpmyadmin and Tomcat 8. Everything is running well.
Now I'm trying to implement the reverse proxy so I can access the tomcat8 not by https://mydominiam.com:8080 but by https://mydominiam.com/tomcat. After reading some tutorials, I can get this code in my /etc/apache2/sites-available/mydomain.com-ssl.conf:
<VirtualHost *:443>
ServerAdmin mydomain#mydomain.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/user/ssl/mydomain.com.crt
SSLCertificateKeyFile /home/user/ssl/mydomain.com.key
SSLCertificateChainFile /home/user/ssl/intermediate.crt
# AJP configuration
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /tomcat ajp://mydomain.com:8009/
ProxyPassReverse /tomcat ajp://mydomain.com:8009/
ProxyPassReverseCookiePath / /
</VirtualHost>
The way the code above is when access https: //mydomain/tomcat, the tomcat home appears, but with broken links.
But if I change the code:
ProxyPass /tomcat ajp://mydomain.com:8009/
ProxyPassReverse /tomcat ajp://mydomain.com:8009/
for
ProxyPass / ajp://mydomain.com:8009/
ProxyPassReverse / ajp://mydomain.com:8009/
The tomcat home reloads usually no broken links, but only through the url https: //mydomain.com
I tried to follow this tutorial, but it still fails. Someone can tell me what I'm doing wrong?

Using ProxyPass with a Tomcat application where you are trying to rewrite the context path (in your configuration above, changing /tomcat to /), there are many many ways your application can break.
It is best to use a configuration like this:
ProxyPass /tomcat ajp://mydomain.com:8009/tomcat
ProxyPassReverse /tomcat ajp://mydomain.com:8009/tomcat
Now, deploy your application as /tomcat instead of the ROOT context. You can easily do that by re-naming the WAR file from ROOT.war to tomcat.war (or re-name the exploded WAR directory from ROOT to tomcat).
If you do the above, you don't have to play any games with rewriting links within pages, etc.

Related

Apache2 as proxy to spring boot application ommiting slashes on login/logout

I am developing a spring boot application which is being deployed on apache2 as a proxy with https. Locally everything works correctly but when I deploy the application to the server whenever I want to access the site that requires authentication I should be redirected to the login page, instead, apache2 just appends "login" to the domain name and displays error as there is no such mapping. The same situation occurs with logout. After invoking /logout there is a redirection to login?logout or login?error, both of this form works correctly as I can access them If I fix link by myself but apache2 just appends "login?logout" to domain name instead of adding slash before. Here is my virtual hosts configuration:
<VirtualHost *:80>
ServerName www.example.com
Redirect / https://example.com
</VirtualHost>
<VirtualHost *:443>
ProxyPreserveHost on
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/ca.crt
SSLCertificateKeyFile /etc/apache2/ssl/ca.key
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

How do I enable a site as a subdirectory of another site in Apache?

I'm trying to enable a service on my home server that has a different document root than my main site. I can't figure out how to edit the site .conf files so that I can run both the main site and the new service.
My use case: I've got a home server running Ubuntu 16.04.1 and Apache 2. I can browse to my site at ceres.local. I also installed OpenProject 6.1. After the install completes, I can browse to that service at ceres.local/openproject, but now browsing to ceres.local returns a 403 Forbidden.
I checked my sites-enabled, and I see that the 000-default.conf is no longer listed, just openproject.conf. So, I ran a2ensite 000-default.conf and service apache2 reload. Now, I can browse to ceres.local, but ceres.local/openproject returns a 404 Not Found.
How do I get both 'ceres.local' and 'ceres.local/openproject' to serve properly with the two .conf files below? Note the different document roots.
My 000-default.conf reads as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName ceres.local
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my openproject.conf reads as follows:
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName ceres.local
DocumentRoot /opt/openproject/public
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
ProxyPass /openproject/ http://127.0.0.1:6000/openproject/ retry=0
ProxyPassReverse /openproject/ http://127.0.0.1:6000/openproject/
</VirtualHost>
I know is a very old post.
But I spend 3 days to solve this and is a first post when we google
so, when you install openproject he create a file called openproject.conf and disable the 000-default.conf
inside this file are a configuration like this
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /opt/openproject/public
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
# Can't use Location block since it would overshadow all the other
#Proxypass directives on CentOS
ProxyPass /help/ http://127.0.0.1:6000/help/ retry=0
ProxyPassReverse /help/ http://127.0.0.1:6000/help/
</VirtualHost>
but when you try acess the mydomain.com you receive the message 403 - forbitten
you just need modify the file like this
Include /etc/openproject/addons/apache2/includes/server/*.conf
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/html # <----- LOCATION WHERE YOU SITE ARE
#DocumentRoot /opt/openproject/public #<--- You Need comment this line
ProxyRequests off
Include /etc/openproject/addons/apache2/includes/vhost/*.conf
# Can't use Location block since it would overshadow all the other proxypass
directives on CentOS
ProxyPass /help/ http://127.0.0.1:6000/help/ retry=0
ProxyPassReverse /help/ http://127.0.0.1:6000/help/
So, if can see the proxypass below, apache will redirect to then when you put mydomain.com/help (you be redirect to openproject), mydomain.com (you main site )
I Hope with this help someone
Be Happy :)

Start two Play! application on same name server

I'm trying to run two different web application on the same server, with the same domain name, like :
www.example.com/app1
www.example.com/app2
The applications are developed using Play! framework, and I'm using Apache as a reverse proxy. I tried to follow the online guide, set up the virtual host and etc..., but nothing seem to works, only the first app is reacheble, while the second isn't.
This is as far as I got untill now with my apache config file :
<VirtualHost *:80>
ProxyPreserveHost On
DocumentRoot "/home/App1/"
ServerName http://www.example.com/app1
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:9000/app1
ProxyPassReverse / http://127.0.0.1:9000/app1
LogLevel debug
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
DocumentRoot "/home/App2"
ServerName http://www.example.com/app2
ProxyPass /excluded !
ProxyPass / http://127.0.0.1:8000/app2
ProxyPassReverse / http://127.0.0.1:8000/app2
LogLevel debug
</VirtualHost>
Route, code and everithing are correct, it's just that I can't get these apps work together.
(I also tried to implement the load balacer showed on the online guide, but it didn't work)
Thanks.
I don't think you can have two virtual hosts with the same host name - that doesn't make sense, virtual hosts are for serving different host names, for example, for serving foo.example.com and bar.example.com.
I think what you want is something roughly like this:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName www.example.com
DocumentRoot /some/path/to/something
ProxyPass /excluded !
ProxyPass /app1 http://127.0.0.1:9000/app1
ProxyPassReverse /app1 http://127.0.0.1:9000/app1
ProxyPass /app2 http://127.0.0.1:8000/app2
ProxyPassReverse /app2 http://127.0.0.1:8000/app2
LogLevel debug
</VirtualHost>
James' answer is correct, you just need to fit it to your needs, I shoot that works out of the box:
<VirtualHost *:80>
ProxyPreserveHost On
ServerName www.example.com
ProxyPass /app1 http://127.0.0.1:9000/
ProxyPassReverse /app1 http://127.0.0.1:9000/
ProxyPass /app2 http://127.0.0.1:8000/
ProxyPassReverse /app2 http://127.0.0.1:8000/
</VirtualHost>
Note, that you will need to prefix EVERY route in your apps to reflect the folder path with app1 and app2, like:
foo site
bar site

How to prevent tomcat7 repeat context name in apache proxy setup

I have this problem where my apache forward http request to tomcat using proxy (see my apache virtual host config below).It works fine, but the web http request http://subdomain.example.com/xyz/images/background2.jpg arrive at tomcat as /xyz/xyz/images/background2.jpg. context name "xyz" appear twice which cause missing resource at tomcat end.
How do you resolve this problem ?
Apache Virtual Host config file
<VirtualHost *:80>
ServerName subdomain.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.example.com:8080/xyz/
ProxyPassReverse / http://www.example.com:8080/xyz/
</VirtualHost>
Tomcat project setup: ../tomcat7/webapps/xyz/...
You need to update ProxyPass settings as below.
ProxyPass /xyz/ http://www.example.com:8080/xyz/
ProxyPassReverse /xyz/ http://www.example.com:8080/xyz/

My PHP WebApps are not found when using Apache ProxyPass to connect to Tomcat Java WebApps

I have apache-http setup using proxypass mod to tomcat:
<VirtualHost *:80>
ServerAdmin john#doe.com
ServerName <my domain>.com
ServerAlias www.<my domain>.com
ProxyPass / ajp://localhost:8080/<web-app context root>/
ProxyPassReverse / http://localhost:8080/<web-app context root>/
ErrorLog logs/<my domain>.com-error_log
CustomLog logs/<my domain>.com-access_log combined
</VirtualHost>
Using this configuration all the traffic is forwarded on great.
However, I also have some php pages on the apache and with this configuration I get a HTTP-404.
Is it possible to mix php sites and have this setup with java hosted sites too?
You can add exclusions using ! syntax.
ProxyPass /phpmyadmin !