Apache Reverse proxy not loading entire app - apache

I have setup Apache reverse proxy on Ubuntu 16 as i want to be able to access multiple apps from a single IP but these apps are distributed across a few different machines.
Below is my current apache conf file. The apps seem to be redirecting but not loading all of the content.
<VirtualHost *:80>
ProxyPreserveHost On
RewriteEngine On
ProxyPass /projects http://x.x.x.12:zzzz/
ProxyPassReverse /projects http://x.x.x.12:zzzz/
ProxyPass /assets https://x.x.x.3/
ProxyPassReverse /assets https://x.x.x.3/
ProxyPass /support http://x.x.x.12/
ProxyPassReverse /support http://x.x.x.12/
ProxyPass /portainer http://x.x.3.x:yyyy/
ProxyPassReverse /portainer http://x.x.x.12:yyyy/
</VirtualHost>

Related

Reverse proxy through Apache with Docker GitLab

I have set up the following VirtualHost in my httpd.conf
<VirtualHost *:80>
ProxyRequests On
ProxyPreserveHost On
ProxyPass /gitlab http://190.22.22.40:6060/gitlab
ProxyPassReverse /gitlab http://190.22.22.40:6060/gitlab
</VirtualHost>
EXPECTED
When I try to load the URL, http://190.22.22.40/gitlab, I want to go to the actual GitLab page to sign in as a new user
ACTUAL
I am redirected to a blank page with the url http://190.22.22.40/users/sign_in
QUESTION
How can I go to the login page with the URL http://190.22.22.40/gitlab and NO port specified in the URL?
Gitlab do not use context to separate multiple application as there is only one.
You need to proxy pass "/" and not "/gitlab" eg:
<VirtualHost *:80>
ProxyRequests On
ProxyPreserveHost On
ProxyPass / http://190.22.22.40:6060/
</VirtualHost>

Apache2 proxy reverse broken Tomcat8 links

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.

VirtualHost Same ServerName Different Directories

I have a running production website assigned to a host (redmine application). I need to add a new application to the same host as a sub-directory.
This is the current virtualhost configuration for redmine application which runs at base folder of host.
<VirtualHost *:80>
ServerName redmine.hostname.com
DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"
RewriteEngine On
RewriteRule ^/(.*)$ balancer://redminecluster%{REQUEST_URI} [P,QSA]
ProxyPass / balancer://redminecluster
ProxyPassReverse / balancer://redminecluster
<Proxy balancer://redminecluster>
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>
</VirtualHost>
So this application already runs at redmine.hostname.com. I want to add my own application and i want it to run at redmine.hostname.com/myapp/.
Whatever i did, i couldn't achieve this. I must not change the path of redmine, i must add new app to same virtualhost. There are no open ports other than 80, so i must make it run at redmine.hostname.com/myapp/
Basically, the redmine application must reply all requests that do not start with redmine.hostname.com/myapp/. My App should reply all requests that start with redmine.hostname.com/myapp.
What settings should i use?
If your application /myapp is located is c:/myappdir, the easiest way to configure apache to do what you want is to use this configuration:
<VirtualHost *:80>
ServerName redmine.hostname.com
DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"
Alias /myapp "c:/myappdir"
ProxyPass /myapp !
ProxyPass / balancer://redminecluster/
ProxyPassReverse / balancer://redminecluster/
<Proxy balancer://redminecluster>
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>
</VirtualHost>
Using an exclamation point as target for ProxyPass will exclude /myapp from the proxy configuration as documented here. Additionally you don't need a special RewriteRule since you don't modify the requests to redmine, ProxyPass should be enough.
It depends a little on whether your own app is hosted on the apache server itself, or it's proxied to another server/process.
If it's on the apache server itself, then just put 'myapp' into the document root. Then you need to remove your ProxyPass line and replace it with a locationmatch block
<VirtualHost *:80>
ServerName redmine.hostname.com
DocumentRoot "C:/BitNami/redmine-2.5.1-1/apps/redmine/htdocs/public/"
RewriteEngine On
RewriteRule ^/(.*)$ balancer://redminecluster%{REQUEST_URI} [P,QSA]
<LocationMatch "^(?!/myapp)">
ProxyPassMatch balancer://balancer://redminecluster
</LocationMatch>
ProxyPassReverse / balancer://redminecluster
<Proxy balancer://redminecluster>
BalancerMember http://127.0.0.1:3001
BalancerMember http://127.0.0.1:3002
</Proxy>
</VirtualHost>
So, the strategy is to forward everything which doesn't match /myapp to your existing redmine application. Everything matching /myapp will go to the document root. If your own app is proxied, then you need another locationmatch block which proxies /myapp to the correct location.

When default virtualhost is not available, no virtual hosts are available

I have an apache2 instance proxying requests to several tomcat instances. Sometimes the default virtualhost is unresponsive (tomcat is running but app not responding). When this happens none of the other virtual hosts are reachable through apache but they work going direct to tomcat. Should the default virtualhost be a static page to avoid this issue? Any other settings to tell apache to skip the default if it doesn't respond?
In the httpd.conf there are proxypass/proxypassreverse statements outside of the virutalhost blocks. I don't know if that could be confusing things.
ProxyPass /test/ ajp://localhost:9009/test/
ProxyPassReverse /test/ ajp://localhost:9009/test/
ProxyPass /test2/ ajp:/localhost/9010/test2/
ProxyPassRevers /test2/ ajp://localhost:9010/test2/
NameVirtualHost 192.168.0.1:80
VirtualHost 192.168.0.1:80>
ServerName test.domain.com
ProxyPreserveHost On
ProxyRequests Off
...
ProxyPass / ajp://localhost:9009/test/
ProxyPassReverse / ajp://localhost:9009/test/
...
/VirtualHost>
VirtualHost 192.168.0.1:80>
ServerName test2.domain.com
ServerAlias test2
PorxyPreseveHost On
ProxyRequests Off
...
ProxyPass / ajp://localhost:9010/test2/
ProxyPassReverse / ajp://localhost:9010/test2/
...
/VirtualHost>
Solaris 10
apache 2.2.6
mod_proxy_ajp
It would be suggested to put ProxyPass parameters in VirtualHost section only.

Apache Config to send sub dirs to different servers - mod_proxy

We use Apache as a reverse proxy server. This has been working well, but I now need to have http://domain.com/sub1 proxy to serverA and http://domain.com/sub2 proxy to serverB. Is this possible? If so, what is the config for it?
Here is my existing config:
...
<VirtualHost 555.55.555.555:80>
ServerName domain.com
DocumentRoot c:/docroot
ProxyPass / http://serverA/
ProxyPassReverse / http://serverA/
</VirtualHost>
...
You've almost got it. You want something like:
ProxyPass /sub1 http://serverA/
ProxyPassReverse /sub1 http://serverA/
ProxyPass /sub2 http://serverB/
ProxyPassReverse /sub2 http://serverB/
Check out the documentation for the ProxyPass directive, there are some neat tricks you can do with it.