Skip to main content

Tomcat port and Apache redirection

This update briefly describes the installation of Tomcat and Apache. 
 

Install and set up Tomcat

 
Reference: 
Digital Ocean
Highly suggest moving to reference when install. It provides detailed description. 
 
 

Install Java 

 

Create Tomcat user on Linux

sudo groupadd tomcat
sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat
 
 

Download Tomcat 

Tomcat download https://tomcat.apache.org/whichversion.html
(I’m using Tomcat 9)
wget -url-get-from-download-page-in-tar-gz-
sudo mkdir /opt/tomcat
sudo tar xzvf apache-tomcat-*tar.gz -C /opt/tomcat --strip-components=1
 

Update Permission

cd /opt/tomcat
sudo chmod -R g+r conf
sudo chmod g+x conf
sudo chown -R tomcat webapps/ work/ temp/ logs/
 

Create systemd service file (Ubuntu service)

sudo update-java-alternatives -l
It shows Java Home
sudo vi /etc/systemd/system/tomcat.service
Edit Environment=JAVA_HOME
sudo systemctl daemon-reload
sudo systemctl start tomcat
sudo systemctl status tomcat
sudo lsof -i tcp:[PORT]
Highly recommend to verify if the port successfully binds. 
 
(my server port 8080 was already enabled while tested Maven)
 

Add manager role on Tomcat

 
At first I wanted to deploy a webapp from Maven pom with a Tomcat Role. Therefore I created a role on Tomcat. But not successful; not yet figured out why JSP content was errors…  
sudo vi /opt/tomcat/conf/tomcat-users.xml
 
Edit
<tomcat-users . . .>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>
 
Edit
sudo vi /opt/tomcat/webapps/manager/META-INF/context.xml
 
Edit
sudo vi /opt/tomcat/webapps/host-manager/META-INF/context.xml
 
comment out localhost only
Edit context.xml
put <!-- --> on item with allow="127
 
sudo systemctl restart tomcat
 

Test Tomcat Server

http://server_domain_or_IP:8080
http://server_domain_or_IP:8080/manager/html
http://server_domain_or_IP:8080/host-manager/html/
 

SSH file transfer

 
I don’t want to use ftp, but now I need to upload a war file to Tomcat management GUI. I found putty’s family also provides ssh file transfer. psftp was installed together with putty. 
 
psftp -i "C:\path\mykey.ppk" user@example.com
 
https://superuser.com/questions/1445476/psftp-connection-using-key-authentication
https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter6.html
Putty man page: https://www.mankier.com/1/psftp
Putty official site: https://www.puttygen.com/
Other reference: ssh & sftp
Ssh official site: https://www.ssh.com/ssh/sftp/
https://www.cs.fsu.edu/~myers/howto/commandLineSSH.html
 
 

Install Apache on Ubuntu

Since I can’t get port 80 working on Tomcat, I installed Apache. 
Ubuntu tutorial: https://ubuntu.com/tutorials/install-and-configure-apache
sudo apt update
sudo apt install apache2
 
…..yes… Currently I only use the install command. I may need to set up other servers, but later, when I have my domain..
 
sudo systemctl restart Apache2 

I’m using Azure VM, having no root password. Command “service restart Apache2” was not valid. Maybe I can use “sodu -S” to set root pw; just not willing to. 
I created /etc/apache2/sites-available/some.service.conf, cleaned up all contexts I thought irrelevant (i.e. folder path… too wrong...) I tried redirect and proxy and both failed. I tried something I familier, .htaccess
 
sudo vi /var/www/.htaccess
Edit
Redirect /virtual-folder http://some.web.site/some-folder
 
And it sill failed!! Then I found the webroot was set with no override… 
https://www.keycdn.com/support/htaccess-not-working
sudo vi /etc/apache2/apache2.conf 
Edit AllowOverride All for webroot. Then .htaccess was working. With port number….. 
 
Eventually, I have to resolve apache proxy…. Luckily I found up-to-date information on digital ocean.
https://www.digitalocean.com/community/tutorials/how-to-use-apache-as-a-reverse-proxy-with-mod_proxy-on-ubuntu-16-04

Validate modules 
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
 
Update default sites-available/000-default.config (I should make a copy instead modify it…)
/etc/apache2/sites-available/000-default.conf
 
Add
ProxyRequests On
 <Location /virtual-folder>
ProxyPass  http://some.web.site/some-folder
ProxyPassReverse  http://some.web.site/some-folder
</Location>
 
Finally…. A http server with tomcat support completed… 
 
 

 
If you want to have a server using port:80(http), you need to set up service with root priority. It might be a difficult status if physical servers are shifting to cloud VM services. Because cloud service providers need to maintain their services, the VM a developer got might still be under a certain shell other than OS. If a developer breaks his/her own VM from service providers, at the worst situation,  the VM was updated to reject connection or privilege and lost control forever. VM is only a block of storage space somewhere on a blade. No one can trace it back since it breaks up with all the rest. 
 
I want the Unity game to report to a server, and the server shows content. When you want to open a public demonstration website, it is suspicious to append a port number on the server name. I set up a Tomcat server, and filed to bind 80 port on the server host. Of course, I don’t accept “impossible”; I successfully used iptable redirect requests from 80 to 8080. This means I lose support of firewall a cloud service provider designed to apply on a ‘expected server’.  I have to install Apache. And then couldn’t find the config……. This version of Apache on Ubuntu was very different from what I knew when I was dealing with a physical server. It took me some time to fix “supposed existing” privileges and to trace out modules must-have. 
 
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
https://www.cyberciti.biz/faq/linux-port-redirection-with-iptables/
 
 
Motivation is always important to me. If the requests come from my clients or employers, the motivation is absolutely enough once mutual agreements reached, no matter how difficult, how boring, how stupid, how tedious tasks would be. If the requests come from myself…., priority shifting plays an important role. I have too low motivation if there is little/no further expansion associated with one task. I built a cloud structure on this illustration project. It is meaningless if it can only run locally. It took me two days to figure out and set up the “formal” web server(s). Time is too precious to me. 

Updated all images to my own creation before go public


Comments

Popular posts from this blog

Bookmark service (MongoDB & Spring REST) -2/2

    I accidentally deleted my development VM. I got lucky having the habit of taking notes. This blog is useful. Development VM is doom to be lost. Rebuild it waste time, but having a clean slate is refreshing~. What concerns me more is my AWS free quota this month is reaching 85%. The second VM I launched but never being used might be the one to blame. (Of course, my mistake.) I terminated the wrong VM. Now I got Linux 2 built. Great, just threw away everything happened on AMI.  1st layer: Page Page class   Originally, I need to prepare getter/setter for all class properties for Spring. By using lombok, I only need to create constructors. lombok will deal with getter/setter and toString(). But there are chances to call getter/setter, but how? .......Naming convention.... Capitalize the 1st character with the prefix get/set.  Annotation @Data was used on this class.  Repository class Spring Docs: Repository https://docs.spring.io/spring-data/mongodb/docs/3....

gamer's interview

This project simulates a gamer's interview. Based on NodeJS+ ReactJS The setting is interviewing a gamer/journalist what's his/her plan of March 2020? The gamer answers his/her game list in plan, how many reviews on demand and how many hours expected. Games selected for review take 5 hours for each, while others take one. This project is designed to practice render html, jsx, component, props introduced in  https://www.w3schools.com/REACT/default.asp . Also fixed other issues to make it work. When trying to modualize objects and tools, my design developed to separate views and processes. And it is quite similar to the initialized structure NodeJS+ReactJS provided. Furthermore, since include local module files are banned by browsers, use NodeJS service seems to be the best option. view file main process object tool

Comments for my Server/Client Web API samples

        Finally, I finished the comments for python/07 and 09 projects. I almost forgot to put the date on source code which is used to note how long it took me. Not precisely in hours….. I didn’t include source code in my previous post. If choosing code-section for this post…… maybe I want to mark out my comment….. (Really?!)          Once my work was developing websites for enterprises, including ERP, CRM or content sites. The sustainability of network and security are important issues. There are 2 methods for HTML Form submission: GET and POST. Submit via POST is secure, compared to GET which piles parameters on URL. RESTful API is mainly using GET.         Yup, even if you have a certification key, if you put the value on the URL, it is visible data. When writing socket-communication, client-server sockets are a pair; both follow the agreement on commands and structures; and there are countless ports for usa...