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
Post a Comment