0

My website is deployed on Tomcat which in turn in deployed on Ubuntu server. While developing the website I access it using server IP address like xxx.xxx.xxx.xxx:8080:/yyyy. Now I have bought a domain name and did a step to redirect www.mydomain.com to xxx.xxx.xxx.xxx. When I try to access my wesite via www.mydomain.com I get Apache Test Page. Could someone provide link or explain remaining steps I need to take to be able to reach my website?

2
  • Change "8080" to "80" - - stackoverflow.com/q/18415578/3395469 Commented Sep 28, 2017 at 15:49
  • Are you using port 80 (or default) when using www.mydomain.com? Is you app properly deployed on the Apache server?
    – xenoid
    Commented Sep 28, 2017 at 16:32

1 Answer 1

0

Figured it out with a help of:

Almost perfect solution for me but port forwarding had to be done differently: https://www.digitalocean.com/community/questions/how-to-access-a-java-web-application-by-a-domain-name-using-tomcat-8

About port forwarding: https://www.systutorials.com/816/port-forwarding-using-iptables/

With a help of this article and the post of Robert Goley I figured the port "forwarding" commands I actually needed: https://askubuntu.com/questions/104824/port-forward-to-a-port-on-the-same-machine

So it all came to these steps:

  1. Stopping Apache2 server on my Ubuntu
  2. Editing Host config in the Tomcat's server.xml to look like:

     <Host name="mydomain.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
          <Alias>www.mydomain.com</Alias>
          <Context path="" docBase="mydomain_appname" debug="0" privileged="true" />
          <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false"/></Host>
    
  3. Then I ran these commands but latter deleted the rules I saw in the iptables (don't know how much of an impact rules 1 and 3 had):

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j DNAT --to XXXXX:8080

iptables -A FORWARD -p tcp -d XXXXX --dport 8080 -j ACCEPT

iptables -t nat -A POSTROUTING -j MASQUERADE

  1. And finally I ran:

sudo iptables -t nat -I PREROUTING -p tcp --dport 80-j REDIRECT --to-ports 8080

sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport 80-j REDIRECT --to-ports 8080

In the end: now I can access my website with www.mydomain.com as any other website. Port 8443 remains in the URL when I acces secure pages though. Need to fix that.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .