Tomcat Apache port 80 port 8080 - apache

I have a vps that runs tomcat 8.0.23 and apache httpd server.
in tomcat i have 3 projects lets call them by names below:
/firstpro
/secondpro
/thirdpro
and i have a domain name lets call it www.mydomain.com
now what i wanna do if request comes to www.mydomain.com i want to forward it to
my.vps.ip.address : 8080/firstpro
the code below is my virtualhost configuration file:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
ProxyPreserveHost On
ProxyPass /firstpro http://localhost:8080/firstpro
ProxyPassReverse /firstpro http://localhost:8080/firstpro
</VirtualHost>
so, problem comes when i type in browser:
if i go to this url: www.mydomain.com i dont get any cookies that automatically my server generates for that session
but if i go to url: www/mydomain.com:8080/firstpro everything works fine
thanks for reading all this. and i would be glad if someone could help me to figure it out

You may need a ProxyPassReverseCookieDomain since you're forwarding between your domain and localhost. – Joachim Isaksson 3 hours ago

Related

Two Domains, One Apache Server. One Tomcat Server. How do I configure Apache to redirect one doamin to Tomcat?

I have two domains domainA.com and domainB.com that both point to the same IP address/server. On that server...
I have an Apache2 web server serving port 80
I have a TomCat9 serving port 8080
I want to redirect all requests (including "/") to the default port 80 of domainB.com to the TomCat9 server on port 8080, whilst leaving all traffic to domainA.com to be handled by the Apache2 web server.
Can anyone recommend a simple recipe for achieving this?
I have looked at https://tomcat.apache.org/tomcat-4.1-doc/proxy-howto.html but got somewhat lost.
May have been easier than I had expected.
I just added the following to /etc/apache2/sites-enabled/donainB.conf
<VirtualHost *:80>
ServerAdmin michael.ellis#myemail
ServerName domainB.com
ProxyPass / http://localhost:8080/
</VirtualHost>
I have no idea if this is the correct thing to do, but it seems to be doing the job.

Apache reverse proxy, one server, multiple domains

I am trying to manage 2 domains with one server (running proxmox with several CT), I am using reverse proxy but seems to be wrong.. here's my configuration:
Let's say we have the main server running proxmox where I managed IPTables to redirect port 80 to the port 80 of my first container (CT01) and port 8109 to port 80 of my second container (CT02).
While using the port in my browser, everything is working well, and I am able to reach each container.
I bought 2 domain names, one for my private server (CT01) and another one for a business server (CT02). I associated both of the domain to my server address, and while typing one or another of them I am redirected to CT01 (normal, browser is running the address to the default port).
So now I tried to use reverse proxy in order to redirect to the desired server (DomainA -> CT01, DomainB -> CT02), I created 2 files in /var/apache2/sites-available/ :
/var/apache2/sites-available/domainA.com:
<VirtualHost *:80>
ServerName domainA.com
DocumentRoot /var/www/
</VirtualHost>
/var/apache2/sites-available/domainB.com:
<VirtualHost *:80>
ServerName domainB.com
ProxyPreserveHost On
ProxyRequests On
ProxyPass / http://x.y.z.h:8109/
ProxyPassReverse / http://x.y.z.h:8109/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
Then I runned a2ensite domainA.com and a2ensite domainB.com. I restarted my apache service.
But nothing have changed: both my domainA and domainB redirect me to the same container (CT01).
Any idea?
What i may suggest is doing a new CT just to host a proxy (nginx for example) that will route the requests to one or the other site depending of the Host: field value of the HTTP request. This may be a little bit overkill if it's just for two sites, but when you want to have more, it can be very useful. Plus the NGinx can be used to cache, etc.
Let me know if you are interested. I know a tutorial that you may follow, but it's in french : http://blog.ganbaranai.fr/2013/08/il-etait-une-fois-proxmox-derriere-une-ip-unique/
Hope it helps.
Regards,

Easy configuration for domain:8080 to 80 Tomcat

Is there an easy way to change from domain.com:8080/myapp to domain.com? Any step by step working examples for Tomcat 7?
Yes, you can use Apache Mod_Proxy for this. You use Apache2 as a front-end to your Tomcat instance.
Here is a configuration example:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName site.domain.com
Redirect / /tomcat-context/
ProxyPass /tomcat-context/ http://127.0.0.1:tomcat-port/tomcat-context/
ProxyPassReverse /tomcat-context/ http://site.domain.com/tomcat-context/
ProxyPreserveHost On
</VirtualHost>
You can find more infos here.
It may seem a bit hard to grasp at first if you're not an Apache2 expert (I am not), but once you've configured your first frontend, adding more and more tomcat instances behind it is a breeze.
Or if you're lazy, change the connector port from 8080 to 80 in the conf/server.xml file in your tomcat home directory.

Redirect URL path to forward to tomcat servlet using Apache/mod_proxy

I currently have a tomcat servlet 1 running under the ROOT:
api1.myhost.com:8080/
I'm using mod_proxy and simply forwarding all requests from
api1.myhost.com to this instance. This is working as of today.
I now have installed a second servlet 2 which runs under the same instance of tomcat (same IP address):
www.myhost.com:8080/servlet2
I want all requests to a new URL api2 to go to that second servlet such that:
api2.myhost.com
now gets forwarded to the second servlet instance.
I've created an A record such that api2.myhost.com points to my server IP. How do you make api2.myhost.com forward to www.myhost.com:8080/servlet2 ?
You need to make two VirtualHost's with on pointing to the first webapp, the other to the second.
<VirtualHost *:80>
ServerName api1.myhost.com
ProxyPass / http://api1.myhost.com:8080/
ProxyPassReverse / http://api1.myhost.com:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName api2.myhost.com
ProxyPass / http://www.myhost.com:8080/servlet2
ProxyPassReverse / http://www.myhost.com:8080/servlet2
</VirtualHost>
Note that since the path will be different on tomcat than on apache, you will need to use relative URLs in your application.

Redirecting an internal path to a virtual host

I have been working on a drupal test site for a while, which has a bunch of virtual hosts set up like this:
<VirtualHost *:80>
ServerAdmin email#example.com
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
</VirtualHost>
I have been using a modified host file to view each of these test sites, along the lines of:
12.0.0.1 localhost
20.02.2.22 testsite1.example.com
20.02.2.22 testsite2.example.com
20.02.2.22 testsite3.example.com
This has worked fine, however now I need to send the sites over to some people remotely who are not technical enough to modify their own host files and see it the way I do.
Is there a way I could set up Apache so that the url "http://20.02.2.22/testsite1" would forward to testsite1.example.com internally? I am using Drupal, and the site setup needs to see the "testsite1.example.com" so that it can correctly choose the instance to select. I have been looking through apache rewrite, but I am a bit of a newb at this so any help is much appreciated.
testsite1.example.com will only be resolved on your machine, so you cannot redirect. You can set up proxy with mod_proxy. Hope this works for you:
<VirtualHost *:80>
ServerAdmin email#example.com
DocumentRoot "/path/to/root"
ServerName testsite1.example.com
ServerAlias 20.02.2.22
<Location /testsite1/>
ProxyPass http://testsite1.example.com/
</Location>
</VirtualHost>
The way I show my local test sites is a combination of Dynamic DNS and port-forwarding.
Internally, my Drupal site is at [my machine ip] or localhost.
I setup a free dynamic dns name to my IP and then on my router, accept incoming requests on port to route to [my machine ip]
That way, they can see yoursite.dyndns.com, but its looking at your local copy.
Why you just don't buy a new domain name and point it to your server IP address...
Or there are free domain solutions like:
http://www.dot.tk/en/index.html?lang=en
or
http://dyn.com/dns/
If you wanna buy new domain, i recommending you this one, cheap and quality service: http://server2.elite7hackers.us/recommend.php?site=godaddy