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.
Related
I have two management console wildlfy and I want to access to both of them through reverse proxy. For that I did this conf in my httpd reverse proxy:
<VirtualHost X.X.X.X:80>
ServerName reverse.com
ProxyPreserveHost On
RewriteEngine On
<Proxy balancer://wildfly-1>
BalancerMember http://wildfly-1.com route=wildfly-1 disablereuse=On keepalive=On retry=20
ProxySet lbmethod=bybusyness
</Proxy>
RewriteRule ^/wildfly-1-console/?$ / [R]
ProxyPass / balancer://wildfly-1/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / balancer://wildfly-1/
<Proxy balancer://wildfly-2>
BalancerMember http://wildfly-2.com route=wildfly-2 disablereuse=On keepalive=On retry=20
ProxySet lbmethod=bybusyness
</proxy>
RewriteRule ^/wildfly-2-console/?$ / [R]
ProxyPass / balancer://wildfly-2/ stickysession=JSESSIONID nofailover=Off
ProxyPassReverse / balancer://wildfly-2/
</VirtualHost>
My problem is that when I enter http://X.X.X.X:80/wildlfy1 or 2 it works, the rewriterules works perfectly and redirect to the management console, But only for the first console. I think that the problem is with my rewriterules, it redirect to the same path "/", so my reverse ignore the second redirection. How can I solve that ?
Thanks.
this was to long or a comment. This is what I meant:
<VirtualHost X.X.X.X:80>
ServerName reverse.com
ProxyPreserveHost On
RewriteEngine On
ProxyPass /wildfly-1-console http://wildfly-1.com
ProxyPassReverse /wildfly-1-console http://wildfly-1.com
ProxyPass /wildfly-2-console http://wildfly-2.com
ProxyPassReverse /wildfly-2-console http://wildfly-2.com
</VirtualHost>
This way heach URL is served via a proxy to another site.
Note that this is far from a complete configuration, it is just to show the concept. I was also no able to test it, as I have no access to an Apache right now.
As for the sticky session, you are applying balancer concepts to a single member, so it serves no purpose. The sticky cookie is to ensure you will return to the same instance for every request. Here is you ask for no1, you get no1. If you ask for no2, you get no2. It is not possible for you to ask for /wildfly-1-console and be "proxied" to http://wildfly-2.com.
Now if you want to have a single URL to proxy in front of http://wildfly-1.com AND http://wildfly-2.com, that is a subject for another question (well some research on your part :-)
I have multiple applications deployed in Tomcat's webapps folder (app1.0, app1.1, app1.2 etc.). When I hit www.example.com:8080/app1.0, the corresponding application appears.
But how to do it on the load-balancing server? For instance, I have a website on which I can click a button (app1.0, app1.1, app1.2 etc.) and an URL pops up like: www.lb.com/app1.0/.../... How to direct to the app based on application version in URL? Use RewriteCond and regex and pass it to ProxyPass? I don't really how to script it, anyone could help? :)
Edit: This is what I done for the 2 apps for 1 Tomcat and 2 apps for 2 Tomcat, but I got 404 sometimes because the Tomcat that has another version has been chosen by the load-balancer.
<VirtualHost *:80>
#Add a http header to explicitly identify the node and be sticky
Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
#Declare the http server pool
<Proxy "balancer://plf">
BalancerMember "http://worker1.com:8080" route=worker1
BalancerMember "http://worker2.com:8080" route=worker2
ProxySet stickysession=ROUTEID
ProxySet lbmethod=bybusyness
</Proxy>
#Common options
ProxyRequests Off
ProxyPreserveHost On
#Declare the redirection for the http requests
ProxyPassMatch "/app(.*)" "balancer://plf/app$1"
ProxyPassReverse "/app(.*)" "balancer://plf/app$1"
This is how I did it:
1) define a balancer proxy:
<Proxy balancer://portalcluster stickysession=JSESSIONID>
BalancerMember ajp://TOMCATSERVER1:8009 route=TOMCARSERVER1-0
BalancerMember ajp://TOMCATSERVER2:8009 route=TOMCATSERVER2-100
</Proxy>
2) proxy to it in your VirtualHost:
Listen 443
<Virtualhost *:443>
ServerName example.com
Alias /static /var/www/portalstatic
ProxyPass /static !
ProxyPass / balancer://portalcluster/
ProxyPassReverse / balancer://portalcluster/
</Virtualhost>
NB I removed a lot of configuration from these, that are not related to the question (logs, deny clauses, certificate directives, ...). This is just to illustrate the way I did the proxy.
NB2 I did leave the /static trick since this is usually something you will want to do. Static files must stay on the HTTP, and not send them from Tomcat all the time.
I want to make Tableau (which is on an internal network) accessible on the public network. One of the ways recommended by Tableau Support is a Reverse Proxy.
I have set up the required modules and have the reverse proxy functioning. The login page is available through these settings in httpd given below. However, once I log in and want to open Projects, Views etc. It routes to
http://actualsite.com/#/vieworproject
which should actually be http://actualsite.com/tableauaccess/#/vieworproject.
Here is the httpd configuration:
ProxyPass /tableauaccess/ http://tableauserverexample.com/
ProxyPassReverse /tableauaccess/ http://tableauserverexample.com/
<Location /tableauaccess/>
Order deny,allow
Allow from all
ProxyHTMLURLMap / /tableauaccess/
</Location>
This doesnt solve the main issue with #. I tried
ProxyPass /#/ http://tableauserverexample.com/#/
ProxyPassReverse /#/ http://tableauserverexample.com/#
But it doesnt help. Any suggestions?? Thanks!
We had this same issue recently. Your httpd.conf file is technically correct for mod_proxy, however the url you are attempting to use is not supported by Tableau. You cannot use:
http://actualsite.com/tableauaccess
But rather you must use the format:
http://tableauaccess.actualsite.com
We ended up setting up that sub-domain name and then using a VirtualHost block such as:
Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
ServerName actualsite.com
DocumentRoot "/path/path2/pathx"
</VirtualHost>
<VirtualHost *:80>
ServerName tableauaccess.actualsite.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://tableauaccess.actualsite.com/
ProxyPassReverse / http://tableauaccess.actualsite.com/
<IfModule mod_cache.c>
CacheDisable *
</IfModule>
RequestHeader set X-Forwarded-Proto "http" #or "https", depending on preference
</VirtualHost>
Be sure to double-check your Tableau server to update the URL format.
Sources:
https://community.tableau.com/thread/198095
https://community.tableau.com/thread/218678
(I don't have enough reputation points to post all of my sources, but thanks to Tableau community, shanemadden at ServerFault, and the Apache documentation.)
edit: forgot trailing slashes
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
This one's driving me nuts. I have an active and in-use Apache proxy server serving content up on EC2. It's working great, and has a variety of vhosts that are configured like this:
<VirtualHost *:80>
ServerName m.FOO.com
ServerAlias customer.FOO.com
ProxyPreserveHost On
ProxyPass / ajp://10.211.42.48:8009/
ProxyPassReverse / ajp://10.211.42.48:8009/
<Proxy ajp://10.211.42.48:8009/*>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>
These all work great, and I'm having no problems. Now what I'd like to do is move it so instead of a single vhost for each app, I want to have a sub-url on the main site that proxies back to the appserver. So instead of a customer having 'customer.FOO.com', they'll have 'FOO.com/customer/'
Great, sounds easy, right? Yeah, not so much. I edit the vhost entry for 'root' of the server (currently showing the landing page), and add the proxy entries to directories within that. That should do it,right? Yeah, it ain't:
<VirtualHost *:80>
ServerName web01.aws.FOO.com
DocumentRoot /var/www/html
ErrorLog logs/www.FOO.com-error_log
CustomLog logs/www.FOO.com-access_log common
<Location /a>
ProxyPass ajp://10.211.42.48:8009
ProxyPassReverse ajp://10.211.42.48:8009
</Location>
<Location /t>
ProxyPass http://adm01
ProxyPassReverse http://adm01
</Location>
<Proxy ajp://10.211.42.48:8009/*>
Order allow,deny
Allow from all
</Proxy>
</VirtualHost>
If i hit http://www.FOO.com/t/ - I get the internal webserver - it proxies forward correctly, and all is well. If I hit http://www.FOO.com/a/ I get a 404 error. The access log even shows a 404 error.
Note that the ProxyPass AJP entries are identical to what's in the other vhost entry. So why does it work on the root on the other vhost entry, and not as a subdir here on the main vhost?
Halp!
I ended up solving this with one particular hint I found out on a mailing list somewhere. The ProxyPassReverse directive is very touchy, and has one basic function. Anything it matches on the second argument (assuming using the ProxyPassReverse A B form) will be applied to the first argument. So it's critical to make sure the second argument is exactly the redirect that is coming from your application, or else the ProxyPassReverse directive will be ignored.
In my case, what I ended up doing was changing the Location entry to:
ProxyPass /a/ ajp://10.211.42.48:8009
ProxyPassReverse /a/ http://my.apphost.com/
And all started working just fine.