access tomcat application via the domain name - dns

I have a virtual cloud server on aws where there is tomcat 7 running on port 8080 eg. a.x.y.z:8080 (where a.x.y.z is the public ip). I have an application deployed on the tomcat on context path "hello" so that I can access it like a.x.y.z:8080/hello .
Now I have bought a domain name example.com and have translated it to the public ip a.x.y.z so that now I can access my application via the url example.com:8080/hello but actually what I want is that on hitting example.com I would be able to access my application. How to achieve it ?

You can access your tomcat application with your domain name using mod_proxy modules, please login your server and update your httpd configuration with following code.
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8080/
ProxyPassReverse / http://0.0.0.0:8080/
NOTE : Update your correct server IP instead of 0.0.0.0 in above code.

Ok, I solved the issue :
After installing apache2, in the /etc/apache2/apache2.conf file
I appended :
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
Saved the file and restarted the apache2 server.
With this, whenever I hit example.com, I will get the homepage of tomcat (localhost:8080). then i opened the tomcat manager (example.com/manager/html) and stopped & undeployed the application at root (/) path. (As a result of this, whenever you hit example.com, you will no longer see tomcat homepage, instead a blank page)
Now I deployed my application as root in tomcat. If you are using maven you can do so like here .
As a result of this my application was available in example.com .
(If you don't deploy your application as root, you have to access it using example.com/myapp)
Now, whenever I hit example.com myapp will be accessed.

Related

Change name of local web service

I setup a local guacamole server for people in my work to access several VM's that we have running in the server. IN order to access guacamole the have to type http://ip:port/guacamole or after the host override I did in my pfsense DNS resolver http://guac.loc:port/guacamole. The problem is that even that some times is problematic for some of them so I want to do something like http://guac.loc so they can remember it easily. I did it for some with the hosta file but I can't different functionallities for some of them. So can anyone help on how to do that? Can I do it somehow from the web server? Or do I need to setup a DNS Server?
If I understand correctly, you want to have "simpler" URL, without port and "guacamole" path.
Guacamole by default runs under Tomcat on port 8080. However, you can put Apache in front of the Tomcat and proxy request to the guacamole. Apache can proxy and forward all requests to the Guacamole on the given port and path.
Something like the example below should work and also will redirect all http requests to the htpts. It is not mandatory to have SSL enabled, you can proxy http as well.
<VirtualHost *:80>
ServerName guac.loc
Redirect permanent / https://guac.loc/
</VirtualHost>
<VirtualHost *:443>
ServerName guac.loc
SSLEngine on
SSLCertificateFile /etc/ssl/certs/guac-loc.cer
SSLCertificateKeyFile /etc/ssl/private/guac-loc.key
SSLCACertificateFile /etc/ssl/certs/guac-loc-ca.crt
<Location /guacamole/>
ProxyPass http://localhost:8080/guacamole/ flushpackets=on
ProxyPassReverse http://localhost:8080/guacamole/
Order allow,deny
Allow from all
</Location>
</VirtualHost>

how to run multiple cross platform web application on the same server using different ports?

I am running a java web application on tomcat 7.0, which is setup on media temple Ubuntu 16.04 server. The application is running on port 8080, and I have a domain which is binded to the port.
e.g. public-ip-of-server:8080 xyz.com
Now, I want to run a node js application (rocket-chat) on the same Linux server using port 3000. I have configured the whole application, and the application is running on localhost:3000/ but when I am trying to access the application using public IP of the server (e.g. public-ip:3000/), I am not able to access it.
I have allowed the traffic on port 3000 using command,
ufw allow 3000
I also edited apache2.conf,
ProxyPass /rocketchat http://public-ip-of-server:3000/
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module
modules/mod_proxy_http.so
but after changing this parameter I am not able to restart the apache2 service.
so I revert back the changes.
what should I do to run both the application (java and node js) on the same Linux server ? can anyone please help me out.
Just bind nodejs app to interface 0.0.0.0 instead of 127.0.0.1.
In your Apache configuration, you should use the localhost instead of public ip. So instead of:
ProxyPass /rocketchat http://public-ip-of-server:3000/
use:
ProxyPass /rocketchat http://localhost:3000/
I am using Ubuntu server so httpd.conf is not present there, so I have created another file, in sites-available folder of apache2.(e.g xyz.conf).
I have two domain which pointing to the same media temple name server,
I used one domain for pointing tomcat application on port 8080 and another domain for node js application on port 3000, by making virtual host in xyz.conf
<VirtualHost *:80>
ServerName xyz.com
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
<VirtualHost *:80>
ServerName abc.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
After this I enabled proxy mode using command :
sudo a2enmod proxy
And also make this xyz.conf file as site configuration file, using command,
sudo a2ensite xyz.conf
It will ask you to reload the apache2 service,
just reload it and restart,
e.g sudo systemctl restart apache2.service
The problem resolved by forwarding the request, which is received on port 80 of apache2, to tomcat:8080 and nodejs:3000, by creating virtual host.

Node application redirect to subdomain using virtual hosts

I'm trying to create a redirect for my nodejs app running a port 5001 to a subdomain and while I browse my nodejs app, I'm trying to keep the subdomain url.
I'm using Debian 8 and the latest Apache version.
I have the following setup:
A node app running on server at http://example.com:5001
A redirect in apache config
<VirtualHost *:80>
ServerName subdomain.example.com
ServerAlias subdomain.example.com
Redirect / http://exemple.com:5001/
</VirtualHost>
This works fine but the url switches
On my other server using Debian 7, I have the following setup :
<VirtualHost *:80>
ServerName subdomain.example.com
ProxyPreserveHost On
ProxyPass / http://example.com:5001/
ProxyPassReverse / http://example.com:5001/
</VirtualHost>
When I try using the same method on my new server, apache won't restart after changing the virtual host.
What am I doing wrong ?
Thanks

Hide remote Node URL when reverse proxying with Apache

I have a CentOS VPS which is serving HTTP requests via Apache and delivers a HTML site. I am also hosting a Ghost blog on the same VPS, which listens on port 2368. Therefore the main site can be accessed via www.domain.co.uk and the Ghost blog via www.domain.co.uk:2368/blog.
I have configured a Reverse Proxy via Apache so that the port can be hidden from the user, i.e. www.domain.co.uk/blog proxies to www.domain.co.uk:2368/blog.
Is it possible for me to 'hide' the original blog URL so that a user never sees the 2368 port? Therefore, if a user ever accesses www.domain.co.uk:2368/blog this will actually 'redirect' to www.domain.co.uk/blog.
I guess something like a proxy from www.domain.co.uk:2368/blog -> www.domain.co.uk/blog; though this would have to be handled by the node application as it listens on that port?
Virtual Host configuration is as such:
<VirtualHost *:80>
ServerName www.domain.co.uk
ServerAlias domain.co.uk
DocumentRoot /var/www/domain.co.uk/public_html
ErrorLog /var/www/domain.co.uk/error.log
CustomLog /var/www/domain.co.uk/requests.log combined
ProxyRequests Off
ProxyPass /blog http://127.0.0.1:2368/blog
ProxyPassReverse /blog http://127.0.0.1:2368/blog
</VirtualHost>

Apache subdomains on ubuntu server from laptop

I'm on my laptop and I want to create subdomains for the server on my network. On my laptop, I modified my hosts file so that I can access my server with the adress myserver
If I access myserver, I get the default apache server html page saying "it works".
On my server, the default document root is /var/www/
I want to create a subdomain for a user such that I would type user.myserver and access files at /home/user/Websites/
Now, I modified httpd.conf on my server to add:
<VirtualHost *>
ServerName *
DocumentRoot "/var/www/"
</VirtualHost>
<VirtualHost *>
ServerName user.localhost
DocumentRoot "/home/user/Websites/"
</VirtualHost>
Also, my hosts file on my server is modified to:
127.0.0.1 user.localhost
if I put user.myserver on my laptop, my browser says it can't find the server.
What am I missing ?
You don't need to modify hosts file on your server, it's only for server resolving, apache will just listen to what Host header it will receive.
You need to modify hosts file on your laptop to have user.myserver point to the IP of your server.

Resources