configure tomcat7 and apache2 - apache

So I have tried several tutorials, however I am missing something and I hope someone could help me.
I have an ubuntu 12.04 server running with tomcat7 and apache2 and I am trying to reach an application (JSF 2.2) running on tomcat via apache2.
The application running on tomcat is working perfectly fine if I am accessing it like this: example.com:8080/demo.
I am trying to access it via apache2 on the following URL: demo.example.com
So far the main page is loading, but the navigation within the application is not.
If the application is sending me to example.com:8080/demo/page2.xhtml instead of demo.example.com/page2.xhtml I am somehow redirected to
demo.example.com/demo/page2.xhtml and get a HTTP Status 404.
And now the million dollar question: what am I doing wrong?
Here is my httpd.conf file:
<VirtualHost demo.mydomain.com:80>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://localhost:8009/demo/
ProxyPassReverse / ajp://localhost:8009/demo/
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
In the server.xml from tomcat7 I added the following entry:
<Connector port="8009" URIEncoding="UTF-8" protocol="AJP/1.3" redirectPort="8080"/>
In the libapache2-mod-jk "workers.properties" I have the following entries:
workers.tomcat_home=/var/lib/tomcat7
workers.java_home=/usr/lib/jvm/java-8-oracle
ps=/
worker.list=ajp13_worker
worker.ajp13_worker.port=8009
worker.ajp13_worker.host=localhost
worker.ajp13_worker.type=ajp13
worker.ajp13_worker.lbfactor=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=ajp13_worker

Please update ProxyPass setttings as below.
ProxyPass /demo/ ajp://localhost:8009/demo/
ProxyPassReverse /demo/ ajp://localhost:8009/demo/
Or
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/

alternative you can use the http connector (default 8080). these must be activated in server.xml.
ProxyPass /demo/ http://localhost:8080/demo/
ProxyPassReverse /demo/ http://localhost:8080/demo/
if the URI /demo under / to deliver, than follow configuration. For this, however, the links must be relative to demo, otherwise there will be problems
ProxyPass / http://localhost:8080/demo/
ProxyPassReverse / http://localhost:8080/demo/

Related

unable to revere proxy jenkins using apache

I have installed Jenkins and apache2 on my Ubuntu-16.04 serverand both are working fine. Now i want to deploy or configure reverse proxy for jenkins using apache.
Took help from this site to configure. I configured everything as per my need. My configuration file under sites-available folder ci.conf looks like
<Virtualhost *:80>
ServerName jenkins.tre.com
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
<Proxy http://localhost:8080/*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://jenkins.tre.com/
</Virtualhost>
and system hostname abd domain name is
root#tre:~# hostname
tre
root#tre:~# domainname
(none)
When i restarted apache & jenkins and tried to access http://jenkins.tre.com/ the page is not opening, can anyone help me with this.... since iam very much new in to this thing.

remove 8080 port from tomcat url

I am using httpd and tomcat for my web application,
so i want to remove 8080 port which is coming in my url.
i tried following things
Made <Connector port="80" in server.xml but its not working.
Used Proxypass in httpd.conf
<VirtualHost *:80>
ServerName myapp.com
ServerAlias www.myapp.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /MyAppPath http://localhost:8080
ProxyPassReverse http://localhost:8080
but both of the things are not working.
whenever i am hitting www.mysite.com its showing apache 2.2 page.
To reach out to mysite every time i need to put www.mysite.com:8080/
please guide.
Thanks in Advance
Resolved by pointing tomcat to 80 and stoped the httpd service.
Worked for me.

Redirect apache to tomcat

I am trying to redirect domain.com to tomcat7, I tried a lot of configurations and doesnt seem to work...
This is my /etc/tomcat7/server.xml config
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="8443"
proxyName="domain.com"
proxyPort="80"
/>
And this is my /etc/apache2/httpd.conf
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
AddModule mod_proxy.c
ProxyPass / http://domain.com:8080/
ProxyPassReverse / http://domain.com:8080/
<Location "/">
Order allow,deny
Allow from all
</Location>
When i go to domain.com i get this default apache message:
It works!
This is the default web page for this server.
The web server software is running but no content has been added, yet.
When i go to domain.com:8080 i get the tomcat message:
It works !
If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!
This is the default Tomcat home page. It can be found on the local filesystem at: /var/lib/tomcat7/webapps/ROOT/index.html
I loaded few .WAR with tomcat assistant one is called App1.
If i go to domain.com/App1 i get:
The requested URL /App1/ was not found on this server.
But if i use domain.com:8080/App1 the app works properly and shows a for loop for example.
UPDATE: tried /etc/apache2/ports.conf with this config:
Listen 80
ServerName domain.com
DocumentRoot /var/www/domain.com/public_html
NameVirtualHost IP
UPDATE2: i just wiped out my debian and i just used /etc/apache2/httpd.conf to set this: (only with this file I achieved same result as above, still must use domain.com:8080/appname to run an app...)
<VirtualHost *:8080>
ProxyRequests off
ProxyPreserveHost on
ServerName domain.com
ServerAlias *.domain.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
How can I do it to redirect straight to tomcat default message instead of apaches ?
And how to get rid of that :8080 and make apps work on domain.com/appname
After long time this is tha answer:
Edit file: /etc/apache2/sites-available/default
ServerAdmin webmaster#localhost
ServerName domain.com
DocumentRoot /var/www
ProxyPreserveHost on
ProxyRequests off
ProxyPass /phpmyadmin !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
using ! to prevent forwarding phpadmin to tomcat

Apache request in port 80 redirect to tomcat at 8080

I have successfully pointed Apache http request to point to tomcat 8080. but the issue is the images and css are not getting loaded. It still is looking at port 80. The application is hosted in amazon ec2
My tomcat deployed url :
If I type www.abc.com it successfully redirect to my application and shows the welcome page. but the images are not showing.
If I include port 8080 in the url the image are showing. eg:
www.abc.com:8080/WebApplication/img/xy.jpg
server.xml
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Config of httpd.conf in apache
<IfModule mod_proxy.c>
ProxyRequests Off
#<Proxy *>
# Order deny,allow
# Deny from all
# Allow from .example.co
ProxyPass / http://www.sabc.com:8080/WebApplication1/
ProxyPass /WebApplication1/img www.abc.com:8080/WebApplication1/img
ProxyPass /WebApplication1/css www.abc.com:8080/WebApplication1/css
ProxyPassReverse /WebApplication1/css www.abc.com:8080/WebApplication1/css
ProxyPass /WebApplication1/img www.abc.com:8080/WebApplication1/img
ProxyPassReverse / www.abc.com:8080/WebApplication1/
#</Proxy>
First thing is you shouldn't be required to mention ProxyPass settings if you already have below code.
ProxyPass / http://www.sabc.com:8080/WebApplication1/
ProxyPassReverse / http://www.sabc.com:8080/WebApplication1/
Still if there is any requirement to specifically mention it, it seems that code written needs to be rectified for ProxyPass Reverse for images as below.
ProxyPass /WebApplication1/img http://www.sabc.com:8080/WebApplication1/img
ProxyPass /WebApplication1/css http://www.sabc.com:8080/WebApplication1/css
ProxyPass***Reverse*** /WebApplication1/img http://www.sabc.com:8080/WebApplication1/img
ProxyPassReverse /WebApplication1/css http://www.sabc.com:8080/WebApplication1/css

Apache + Tomcat: Using mod_proxy instead of AJP

Is there any way I connect Apache to Tomcat using an HTTP proxy such that Tomcat gets the correct incoming host name rather than localhost? I'm using this directive in apache:
ProxyPass /path http://localhost:8080/path
But it comes through as localhost, which is useless when we have a bunch of sites on the same server. I could set the host manually in the server config:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
proxyName="pretend.host" proxyPort="80" />
But that again doesn't serve more than one site. And I don't like the idea of using a different internal port for each site, that sounds really ugly.
Is there no way to transfer the port when I proxy it?
(If you ask why I don't just use AJP, the answer is this error. I'm trying everything I can before giving up on Tomcat and Apache entirely)
The settings you are looking for are:
<VirtualHost *:80>
ServerName public.server.name
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Note that we're using localhost as the proxy target. We can do this since we enable ProxyPreserveHost. The documentation states that
It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server.
which sounds exactly like what you are doing.
I think your best bet if you want multiple sites on the same server is to use virtual hosts in your Apache configuration. Here's an example:
<VirtualHost *:80>
ServerName server.domain.com
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://server.domain.com:8080/
ProxyPassReverse / http://server.domain.com:8080/
<Location />
Order allow,deny
Allow from all
</Location>
As long as you have server.domain.com registered in your external DNS, the incoming host name will be displayed in client URLs. I'm running a single server hosting 6 separate sites, including 3 that are back by Tomcat, using this method.
You can still use AJP, and you should since it's faster than HTTP. Just make sure to enable it in http.conf:
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
In that case, this configuration works for me:
<VirtualHost *:80>
ServerName public.server.name
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8080/
# ProxyPassReverse might not be needed,
# it's only for redirecting from inside.
# ProxyPassReverse / ajp://localhost:8080/
</VirtualHost>