I just set tomcat on port 80
by adding this on /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin tomcat#something.com
ServerName something.com
ServerAlias www.something.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://something.com:8080/
ProxyPassReverse / http://something.com:8080/
ErrorLog logs/something.com-error_log
CustomLog logs/something.com-access_log common
</VirtualHost>
But now i am trying to access something.com/phpMyadmin
It is redirecting to something.com:8080/something.com
which is a wrong path
Please help
Try adding this line right before your existing ProxyPass:
ProxyPass /phpMyadmin !
It tells Apache not to proxy this path to Tomcat. Everything else will be proxied.
Related
I have a java portal running on Tomcat but I want its static contents(except html) to be served by Apache httpd.
So I've installed an Apache httpd and now I am configuring httpd.conf
I know that I need something like the below text:
<VirtualHost *:80>
DocumentRoot /opt/tomcat/webapps/ROOT
ServerName mywebapp.com
ServerAlias mywebapp.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPassMatch "^/(.*\.gif)$" "ajp://localhost:8009/$1"
ProxyPassReverse / ajp://localhost:8009/
But this is a sample and I do not know how to use RegEx in front of ProxyPassMatch to fulfill my purpose.
My purpose is to serve jpg, jpeg, gif, js, css by Apache httpd
And others serving by Tomcat
I found a solution:
<VirtualHost *:80>
DocumentRoot /opt/tomcat/webapps/ROOT
ServerName mywebapp.com
ServerAlias mywebapp.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
#ProxyPass / ajp://localhost:8010/
ProxyPassMatch ^/(.*(?<!\.jpg)(?<!\.png)(?<!\.jpeg)(?<!\.css)(?<!\.ico)(?<!\.bmp)(?<!\.js)(?<!\.gif))$ ajp://localhost:8009/$1
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
I have a server with CentOS and zpanel installed. Zpanel installed "Apache Httpd" along many other modules. I have been hosting multiple domains without any issue.
I have two issues:
Remove port 8080 and direct all calls to 80.
Appropriate domain for each tomcat app, as well as my existing sites running independently on Apache Http.
I installed apache tomcat 8 and deployed multiple applications and I can access my applications like
http://example:8080/app1
http://example:8080/app2
http://example:8080/app3
What I want is that my tomcat apps are mapped to my domains, such that
http://example:8080/app1 => http://www.app1.com
http://example:8080/app2 => http://www.app2.com
http://example:8080/app3 => http://www.app3.com
I did tried this tutorial which somewhat does trick but not exactly what I want. i.e. after performing the steps he mentioned when I opened my example.com it redirected to my tomcat app like: example.com/app1. [It did removed 8080 and redirected to correct app] BUT if the app from the end is changed i.e. app1 is changed to someother project that is been hosting by tomcat then that project is opened.
Edit:
My virtual host file is
# DOMAIN: app1.com
<virtualhost *:80>
ServerName app1.com
ServerAlias app1.com www.app1.com
RewriteEngine On
RewriteRule ^/$ app1/ [R=301]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /app1 http://localhost:8080/app1
ProxyPassReverse /app1 http://localhost:8080/app1
ErrorLog "/var/zpanel/logs/domains/zadmin/app1.com-error.log"
CustomLog "/var/zpanel/logs/domains/zadmin/app1.com-access.log" combined
CustomLog "/var/zpanel/logs/domains/zadmin/app1.com-bandwidth.log" common
</virtualhost>
Update 1
I tried this as well, but of no use. Am I missing something? please guide.
Have you configured properly your http server ?
For example in your apache2.conf or httpd.conf
#LoadModule directives
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
<VirtualHost *:80>
ServerName www.example.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://example.com:8080/app1
ProxyPassReverse / http://example.com:8080/app1
ProxyHTMLURLMap / /app1/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
After 2 Days of hard search and lots of tests I was finally able to map my domain to tomcat app. Many thanks to these two guides mod_jk installation and vhost/httpd/tomcat
I have been able to map my application to the domain in a manner I found after doing some research (copy-paste) on internet.
<VirtualHost *:80>
ServerName example.com
ProxyPass /MyApp http://localhost:8080/MyApp
ProxyPassReverse /MyApp http://localhost:8080/MyApp
ProxyPassReverseCookieDomain localhost example.com
ProxyPreserveHost On
RewriteEngine on
RewriteRule ^/$ http://example.com/MyApp
</VirtualHost>
The rewrite works fine and whenever I open example.com it redirects to example.com/MyApp . My query is, how can I make it not redirect and deliver the MyApp at example.com/ without any redirect. Just plain simple mapping of the MyApp to the root of the domain. The rewrite works fine, but certainly don't want app name in url.
Rename your war file to ROOT.war to make it the root webapp in Tomcat. Then adjust the paths accordingly in the Apache config:
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
i am using servlet, and i am using this URL
http://s4.com/api/system?section0=report&reportType0=overTime&dataType0
in the browser to request some json data that i create in the servlet
i tried to read the whole URL to get it is first part s4.com in the doGet method since it may came as :
http://s.com/api/system?section0=report&reportType0=overTime&dataType0
http://s1.com/api/system?section0=report&reportType0=overTime&dataType0
http://s2.com/api/system?section0=report&reportType0=overTime&dataType0
http://s3.com/api/system?section0=report&reportType0=overTime&dataType0
http://s4.com/api/system?section0=report&reportType0=overTime&dataType0
.
.
.
http://s100.com/api/system?section0=report&reportType0=overTime&dataType0
so i need to distinguish between them using the s(number).com
in the do get method i tried
request.getRequestURL().toString(); ===== output===> http://localhost:8090/MySim/api/system
and
request.getServerName().toString();===== output===> localhost
and
request.getRequestURL().toString(); ===== output===> /MySim/api/system
and i also tried this
String uri = request.getScheme() + "://" + // "http" + "://
request.getServerName() + // "myhost"
":" + // ":"
request.getServerPort() + // "8080"
request.getRequestURI() + // "/people"
"?" + // "?"
request.getQueryString();
which prints the full path URL
===== output===>
http://localhost:8090/MySim/api/systemsection0=system&type0=shortStatus&rand0=1405835810247&sessionId=FFFFFFFFF
but non of these got the right answer
my a part of web.xml:
<servlet-mapping>
<servlet-name>Api</servlet-name>
<url-pattern>/api/system</url-pattern>
</servlet-mapping>
hosts file :
# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 localhost
127.0.0.1 sim.localhost
127.0.0.1 sim.nma.localhost
127.0.0.1 nma.localhost
127.0.0.1 s.com
127.0.0.1 s1.com
127.0.0.1 s2.com
127.0.0.1 s3.com
127.0.0.1 s4.com
127.0.0.1 s5.com
i am using xhamp server with apatchi so in the Config file i used to the following :
</VirtualHost>
<VirtualHost *:80>
ServerName s4.com
Header add Access-Control-Allow-Origin "*"
ProxyRequests Off
<Proxy *>
Allow from all
</Proxy>
ProxyPass /session/ http://localhost:8090/MySim/session/
ProxyPass /api/ http://localhost:8090/MySim/api/
ProxyPassReverse /session/ http://localhost:8090/MySim/session/
ProxyPassReverse /api/ http://localhost:8090/MySim/api/
</VirtualHost>
<VirtualHost *:80>
ServerName s5.com
Header add Access-Control-Allow-Origin "*"
ProxyRequests Off
<Proxy *>
Allow from all
</Proxy>
ProxyPass /session/ http://localhost:8090/MySim/session/
ProxyPass /api/ http://localhost:8090/MySim/api/
ProxyPassReverse /session/ http://localhost:8090/MySim/session/
ProxyPassReverse /api/ http://localhost:8090/MySim/api/
</VirtualHost>
this is why request.getserverName() always prints local host
and now i edited the config file ass following :
</VirtualHost>
<VirtualHost *:80>
ServerName s4.com
Header add Access-Control-Allow-Origin "*"
ProxyRequests Off
<Proxy *>
Allow from all
</Proxy>
ProxyPass /session/ http://s4.com:8090/MySim/session/
ProxyPass /api/ http://s4.com:8090/MySim/api/
ProxyPassReverse /session/ http://s4.com:8090/MySim/session/
ProxyPassReverse /api/ http://s4.com:8090/MySim/api/
</VirtualHost>
<VirtualHost *:80>
ServerName s5.com
Header add Access-Control-Allow-Origin "*"
ProxyRequests Off
<Proxy *>
Allow from all
</Proxy>
ProxyPass /session/ http://s5.com:8090/MySim/session/
ProxyPass /api/ http://s5.com:8090/MySim/api/
ProxyPassReverse /session/ http://s5.com:8090/MySim/session/
ProxyPassReverse /api/ http://s5.com:8090/MySim/api/
</VirtualHost>
Your client browser connects to
http://s4.com/api/system
but your web applications responds to
http://localhost:8090/MySim/api/system
That is a common use case : it means that you have a HTTP reverse proxy (commons are apache, nginx or IIS) that does the URL rewriting. If it is possible, you should ask the administrator of the proxy how and where you can find the original requested host. If this is not an option, you will have to examine all the headers to try to discover it. For example, Apache mod-proxy normally uses the header X-Forwarded-Host.
I have some trouble with Apache and Tomcat server inside same machine.
I want redirect a virtual host, kb.domain to an tomcat app kb.
I have read some post on internet but I don't found a solution to my problem.
My configuration have one Apache server (http://domain) and in same machine an tomcat server (http://domain:8080); in my Apache I have mapped a VirtualHost that respond to kb.domain like this:
<VirtualHost *:80>
ServerName kb.domain
<Location />
ProxyPass http://192.168.200.3:8080/kb
ProxyPassReverse http://192.168.200.3:8080/kb
</Location>
</VirtualHost>
When I call the kb.domain url from browser he add an extra / at the end and go into redirect loop.
Can anyone help me?
Thanks
Your proxpass directives should be:
ProxyPass / http://192.168.200.3:8080/kb/
ProxyPassReverse / http://192.168.200.3:8080/kb/
try
<VirtualHost *:80>
ServerName kb.domain
ProxyPass /kb http://localhost:8080/kb
ProxyPassReverse /kb http://localhost:8080/kb
</VirtualHost>
If you want to pass regardless of path ( aka not /kb )
<VirtualHost *:80>
ServerName kb.domain
ProxyPass / http://localhost:8080
ProxyPassReverse / http://localhost:8080
</VirtualHost>