Accessing Web application in tomcat without port numbers - linux

I am trying to have multiple tomcat instances on a Linux server and each instance would have an web application ROOT deployed in it.
While accessing the application, the url is formed in the format : whereas I don't want the end users to remember the ip address or the port of the application.
Since more than one instances would be used in the linux server, defaulting to 80 port ( http ) and 443 ( https ) wouldn't help out.
The idea is to expose the DNS name for the application and looks like Apache HTTP server would help me solve the case. Is the approach right ?
I assume the apache server should be one per linux server vs one per tomcat instance. Could this be confirmed ?
The Apache Tomcat version is 8.5.4 and the plan is to go with the apache http server version 2.4

Setting an Apache HTTPD (or any other) as front server is a good approach.
You won't be able to use more than one Apache HTTPD per server, since you don't want to use :port notation in the url's, at least it will not be possible to use standard HTTP/HTTPS ports in more than one HTTPD at once at the same server.
If you plan to use both http and https, you should create at least one virtual host for each of them. There is a limitation on creating virtual hosts for name based virtual host while using SSL 443 port, so if you want to have more than one HTTPS port enabled you will need IP based virtual hosting.
This is the Apache HTTPD 2.4 virtual host documentation.
Then, you could forward requests to each Tomcat using mod_proxy or tomcat connector. I personally choose one or other depending on the current requirements, specially if there is straight correspondence between contexts in Tomcat and Apache HTTPD (in this case I use AJP) or there's the need to rewrite it (mod_rewrite):
httpd://apache.httpd/context1 -> tomcat:XXXX/context1 (ajp tomcat connector)
httpd://apache.httpd/ -> tomcat:XXXX/context2 (mod_rewrite)
httpd://apache.httpd/context3 -> tomcat:XXXX/context4 (mod_rewrite)

Related

Stop apache and run node server

I have a centos 7.9 linux server with whm panel installed. Apache is installed directly on the domain names I created, I don't want to run apache on the subdomain of one domain name. I want to run a node js server. When I say "service httpd stop", they all shut down. What to do?
Network services don't bind themselves to specific hostnames. You have one Apache server running. Any connection to port 80 will connect to that server. Apache then looks at the host header in the HTTP request to determine which website to respond with.
If you want one site to use Node.js then you need to pick one of these options:
Configure Apache to act as a reverse proxy for the Node.js hosted server
Run the Node.js server on a different computer and point the host name at that computer
Have multiple network interfaces for the existing computer, with their own IP addresses, configure Apache to listen on one and Node.js to listen on the other, then point the hostnames at the right IP addresses.
(I don't recommend the last one as it is the most fiddly).

NodeJs instead of Apache

I have a website under domain (say example.com) which is hosted on Amazon Web Services EC 2 instance which has Apache already installed and ready to run on port 80.Now I wish to transfer from Apache to node JS (where Node JS runs on another port, say 8001).How to change the HTTP port address of EC 2 say that when i go to that URL (example.com) it should run on node JS instead of Apache (While for temporary,node JS runs on example.com:8001).
How is it possible and Kindly help?
So you cannot direct a standard web address (e.g. www.example.com) to anything other than port 80. By default http is on port 80 and https is on port 443. You can override that default by explicitly giving the port but you cannot change that default.
So your options are:
Replace Apache with Node on port 80. This will involve shutting down Apache (and making sure it doesn't auto restart on reboot), and changing your node port to port 80. This also will probably require running your node service as root (as port 80 is usually protected) and this is not recommended (Apache starts as root to get the port but then usually immediately switches to non-root user).
Have Apache proxy forward requests to Node. This means Apache is still your main webserver and listens on port 80 but certain requests are sent on to Node.
This second option could be done using mod_proxy with config like this:
ProxyPass "/foo" "http://localhost:8001/"
ProxyPassReverse "/foo" "http://localhost:8001/"
It all depends on what you want to use your set up for and making best use of the software available to you.
Typical set up is a multi-layered approach involving one or more of these:
LoadBalancer (optional for high load sites or where resiliency is key)
Webserver
Appserver
Database
Yes you could use just Node for all of these layers. However, to me, it is more an application server than a webserver.
A webserver like Apache or Nginx is specifically designed to act like a web server, and by that I mean serving static pages and doing other top layer stuff. They have several features built up over their years to provide speed and security. Now nearly everything they can do, can be done in Node but not quite as easily and not by standard and often requires pulling in 3rd party modules.
A webserver then typically offloads dynamic work to other programs. This could be scripts (PHP or Perl), or separate app servers like Tomcat, Jboss or Node. These are typically very good at specific tasks (e.g. talking to database and generating dynamic pages) but less good at severing static pages quickly.
The beauty of node to me is for micro- services, where you can have lots of independent, but potentially interlinked, node services which are all lightweight and good at one task and the web server is still needed in front of them. This compares to a bulky multi-tasking J2EE server like Tomcat or Jboss that you would use in the past which tried to do every dynamic app under one process (though admittedly often under separate WAR files).
So, without knowing your full use case, I would suggest Apache and Node instead of Node replacing Apache.

Solr with Jetty on LAMP server - Admin page access issue

I have Solr with its default Jetty that came with example directory installed on Linux server which has apache2 as its web server.
Now, within the same private LAN, when I open a browser and type in http://<ip-address>:8983/solr works ONLY when I do port forwarding otherwise it doesn't work. I am not sure what could be the problem? Please note this installation has been done on a remote server in a hosting environment for production deployment and I am a beginner wrt deployment stuff.
You can use the jetty.host parameter during startup to allow direct access to Jetty.
The -D option of the java command can be used with the followin syntax:
java -Djetty.host=0.0.0.0 -jar start.jar
In this way Jetty can be reached from all the hosts.
However this is not the ideal setup IMHO. I prefere to setup Jetty to listen only on localhost, implementing the client with another frontend server which listen on port 80. If you want to implement the frontend on another server you can use iptables to limit the incoming connection, dropping everything on the 8983 port if the IP is different from the one of your frontend server.
This image depicts my preferred setup for a LAMP stack includin SOLR:

deploying a node.js on a new domain

I have a server that runs different websites on different ports. All of them (but one) are Apache servers and thanks to webmin, I managed to have, for instance, example.com point to 123.123.123.123:80 and example.fr to 123.123.123.123:8000, somehow automatically
I am now running a nodejs server on the same machine, so the 80, 8000, and many other ports are already taken. My nodejs listens on 8008. I have another domain name, say example.org, and I want it to point to my nodejs website, but I simply don't know how to do that! I have updated the DNS and everything is pointing to 123.123.123.123 (my server's IP). I want to avoid using an ugly example.org:8008/ for everything on this node server. How can I make it point implicitly to the 8008 port?? I must add that I cannot afford to take down the apache servers ;)
DNS only provides name to ip address mapping. It cannot handle ports. What you can do instead is to set up a proxy server listening on port 80. The proxy server can then return data based on the host header.
Your best option is to just redirect the request from Apache. Otherwise you can use a reverse proxy like Nginx. Also, you can write a lightweight proxy in node... check out this page

redirecting from IIS to tomcat?

i have a hosting space in vps. where numerous domains are parked. my domain name is mywebsite.com it is present in c:\uname\mywebsite.com inside the folder there is default.aspx file. when I type in the url as www.mywebsite.com i can see default.aspx page. if i replace with any other page index.jsp i will get the error thrown by IIS server. so, I installed tomcat, java and deployed war file. I have even made changes in server.xml in tag specifing the host name too... how can i redirect the incoming requests to tomcat server? please guide me in it
You need to install a connector.
I would try BonCode: tomcatiis.riaforge.org
The standard way is to go to tomcat.apache.org, and download the ISAPI redirector. This communicates via AJP and you can set it up to redirect various urls to tomcat.
HTTP uses port 80 for connections by default.
One network port (in this case is TCP 80 or the http://example.com:{port}) on each IP can only being listened to by one application.
Yours is currently used by IIS. First you need to do is check what port is used by the Tomcat (refer here).
Then you should try to browse http://example.com:{port in tomcat server.xml} and see if you can view the Tomcat welcome page correctly or not, or your application.
After you verified that the tomcat is working, you can decide to change the Tomcat port number to whatever you want, make sure IIS is shutdown if you want to run it on 80.
Another option is to install Apache on port 80 as a proxy to connect the Tomcat port 8080, this will provide for security and flexibility if you need to extend your infrastructure in the future.

Resources