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>
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 have a tomcat 6.0 web server on my server machine.now i created a glassfish server on the same machine. for avoid port conflict i just change glassfish port to 8081. now how can i access my web applications on both glassfish and tomcat from different DNS name.
Depends on your DNS/server setup.
You could use Apache and reverse proxies:
<VirtualHost *>
ProxyPreserveHost On
# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example:
ProxyPass / http://0.0.0.0:8081/
ProxyPassReverse / http://0.0.0.0:8081/
ServerName glassfish.server
</VirtualHost>
<VirtualHost *>
ProxyPreserveHost On
# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example:
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/
ServerName tomcat.server
</VirtualHost>
Or you could use your DNS. I'm afraid I can't help you with that.
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.