I have been trying to configure my apache server to support virtual hosts, these hosts, would then redirect any request made at port 80 to different applications hosted in a Jboss AS, so for example my configuration would be like this:
<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass / http://localhost:8080/contextPath
ProxyPassReverse / http://localhost:8080/contextPath
ProxyPreserveHost On
ProxyPassReverseCookiePath / /
</VirtualHost>
However the problem is that when I'm trying to access http://www.testdomain.com, the url gets redirected effectively to localhost:8080, however, I got a duplicated context path. I.E: http://www.testdomain.com/contextPath/contextPath.
Any ideas why is this happening. Thanks a lot.
I had the same issue and this was solved by adding forwardslashes to the urls.
ProxyPass / http://localhost:8080/contextPath/
ProxyPassReverse / http://localhost:8080/contextPath/
That solved it for me !
Full example for a single virtual host file. I have several, one for each domain and subdomain.
ProxyRequests Off
ProxyPreserveHost On
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName enter.name.here
ProxyPass / http://127.0.0.1:8080/<contextPath>/
ProxyPassReverse / http://127.0.0.1:8080/<contextPath>/
ErrorLog /var/log/apache2/somelog.log
CustomLog /var/log/apache2/somecustom.log common
</VirtualHost>
You need to remove the "ProxyPass" and "ProxyPassReverse" entries, unless you really are trying to proxy something. If the jboss AS is on another server, then you need to retain the proxy entries, but it looks to me like you might be making it too difficult if the content is on one machine and not multiples.
If you want one server to use different base folders as the root for 2 different domains, then you would need to configure the 2 domains by specifying the DocumentRoot parameter.
for example, if I wanted to host google.com and yahoo.com on one computer, my virtualhost entries would contain:
<VirtualHost *:80>
ServerName www.google.com
DocumentRoot /var/www/Google
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
DocumentRoot /var/www/Yahoo
</VirtualHost>
Then, your root directories for each server will go in the google folder and the yahoo folder, respectively.
If you are trying to proxy a completely different machine, then the following should work:
<VirtualHost *:80>
ServerName www.google.com
ProxyPass / www.google.com
</VirtualHost>
<VirtualHost *:80>
ServerName www.yahoo.com
ProxyPass / www.yahoo.com
</VirtualHost>
Your entry specifically doesn't make much sense. I think it should look like:
<VirtualHost *:80>
ServerName www.testdomain.com
ProxyPass /contextPath http://localhost:8080
ProxyPassReverse /contextPath http://localhost:8080
</VirtualHost>
Related
I am running multiple instance of tomcat on my linux machine. so there are more than one connector ports for different instance like 8080,8081,8082. I want to remove port number from URL.
For example :-
Current url : - www.sushant.com:8081/
Needed :-www.sushant.com/
please suggest me how can i do this.
Thanks.
You should consider using a proxy on your server. There is a really good tutorial at apache.org, using an Apache Web Server.
http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html
This enables you to connect to your server via port 80, which is not printed in the url bar of your browser.
I saw answer above and struggled a bit, so thought of putting up an example since I was on ubuntu, so I had to change apache2.conf file in /etc/apache2/
You can find your apache2.conf file or httpd.conf as per your OS
I added following rules -
<VirtualHost *:80>
ServerName sushant.com
ServerAlias www.sushant.com
ProxyRequests On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:7777/
ProxyPassReverse http://localhost:7777/
</Location>
</VirtualHost>
<VirtualHost *:8081>
ServerName sushant.com
ServerAlias www.sushant.com
ProxyRequests on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:8081/
ProxyPassReverse http://localhost:8081/
</Location>
</VirtualHost>
So, now it works both with and without the port.
I have installed an application with context /sampleApp on Tomcat7 running Linode. I also have an Apache server installed.
I have done some configuration as below, through which I am able to redirect the requests from www.example.com to the root of tomcat. But I want to be able to serve /sampleApp whenever somebody requests the domain name like www.example.com.
Here is the configuration I have done so far:
Included and enabled a virtual host www.example.com in Apache2
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://www.example.com/
</VirtualHost>
And added proxy support in Tomcat7 server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" proxyName="www.example.com"
proxyPort="80"/>
I have search SO and ServerFault and Google too but cant find something that works for me.
Did you add this entry in /etc/hosts?
127.0.0.1 www.example.com
If you did try this:
ProxyPass / http://www.example.com:8080/sampleApp
ProxyPassReverse / http://www.example.com:8080/sampleApp
Otherwise:
ProxyPass / http://localhost:8080/sampleApp
ProxyPassReverse / http://localhost:8080/sampleApp
and remove the proxyPort from your server.xml
ps: remember to restart both tomcat and apache2
I need to have 2 application on Tomcat behind apache virtualhost. Each app gave own domain.
There are my apache virtualhost configs:
<VirtualHost *:80>
ServerName tomcat.example.net
DocumentRoot /var/www/tomcat.example.net
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName domain.tld
DocumentRoot /var/www/tomcat.example.net
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:8080/domain.tld/
ProxyPassReverse / http://127.0.0.1:8080/domain.tld/
</VirtualHost>
By default, all app are accesible through http://tomcat.example.net/APPNAME - it is ok.
Second virtualhost is for app with domain domain.tld.
If I go to app through http://tomcat.example.net/domain.tld/info/ it works good but if I go throug http://domain.tld/ and click on links on page all links link to http://domain.tld/domain.tld/info/ - I see error page.
In JSP page I use c:url so it maybe be good.
<c:url value="/info/" />
I use default tomcat7 settings on ubuntu 12.04 server.
App on subdomain has subdomain/appName in url. On subdomain it is http://domain.tld/APPNAME/info/ (http://domain.tld/domain.tld/info/) but it must be only http://domain.tld/info/ domain.tld=APPNAME
How to config apache/tomcat/my app?
I have an application with spring security. I case the user is not authenticated he is redirected to bo/login page.
The problem is that the way i setup the apache web server in front of the tomcat i produce infinite redirection loop:
<VirtualHost *:80>
ServerName dev.bo.MYDOMAIN.com
ProxyPass / ajp://localhost:20009/bo/
ProxyPassReverse / ajp://localhost:20009/bo/
ProxyPassReverseCookiePath /bo/ /
</VirtualHost>
Does anyone knows how can i prevent the loop in case the user is not authenticated?
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName dev.bo.MYDOMAIN.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:20009/bo/
ProxyPassReverse / ajp://localhost:20009/bo/
</VirtualHost>
Try the above config
Finally i found the problem. I had to proxy also the 'bo' path:
<VirtualHost *:80>
ServerName dev.bo.MYDOMAIN.com
ProxyPass / ajp://localhost:20009/bo/
ProxyPassReverse / ajp://localhost:20009/bo/
ProxyPass /bo ajp://localhost:20009/bo/
ProxyPassReverse /bo ajp://localhost:20009/bo/
ProxyPassReverseCookiePath /bo/ /
</VirtualHost>
Why use mod_jk and mod_proxy? You should just be able to do
ProxyPass / http://localhost:20009/bo/
ProxyPassReverse / http://localhost:20009/bo/
At least you save yourself the protocol switch.
This question has been asked before, and, in resume I want configure this scenario:
1 - I have one Jetty 7 server with many applications, e.g: app1, app2, app3, etc.
2 - I have one main domain, and, one sub-domain per Jetty application, e.g:
app1.example.com, app2.example.com, app3.example.com, etc..
3 - I'm try using Apache 2.2.22 mod_proxy to mask these Jetty applications across domains managed by Apache. This is my functional configuration for one application:
<VirtualHost *:80>
ServerName example.com
ServerAlias app1.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *:80>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /app1 http://localhost:8080/app1
</VirtualHost>
This configuration works, but, it doesn't remove the context name, the URI is:
http://app1.example.com/app1/?args=or/pages/etc...
Have an way to remove this context name, leaving a full transparent URIs ? e.g:
http://app1.example.com/?args=or/pages/etc..
All examples on the web uses this context name on URIS :/
Additional information:
VM with Ubuntu 12.04;
Jetty 7 without modifications;
Apache 2.2.22 with mod_proxy and mod_rewrite enabled (and some basics mods enabled by default);
Correct and valid CNAME and domain name within VM manager at Digital Ocean;
Thanks in advance.
I've found a solution:
1 - Install this specific lib for apache2 mod-proxy-html:
sudo apt-get install libapache2-lib-proxy-html
2 - Enable this new module:
sudo a2enmod proxy_html
3 - Config your application descriptor at:
sudo vim /etc/apache2/sites-enabled/app1
with this content:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName app1.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *:80>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/app1
ProxyPassReverse / http://localhost:8080/app1
ProxyHTMLURLMap / /app1/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
4 - Restart apache2 service:
sudo service apache2 restart
Be happy, transparent requests across:
http://app1.example.com/some/beautiful/page