Search code examples
glassfish-3

HTTP and HTTPS port


I have created a J2EE application that runs on GlassFish, HTTPS enabled. When the user typed http: //www.mydomain.com:8080/app, it will be redirected to https: //www.mydomain.com:8181/app/login.

However, when I see in some of the websites, it can actually redirected to something like https: //www.mydomain.com/app/login (without the HTTPS port 8181). Does this means that the server is running both HTTP and HTTPS on port 80?

How to configure this on GlassFish 3.1?


Solution

  • Non-root user should not use ports below 1024. It is better to do port forwarding from 80 to 8080 and 443 (https default) to 8181.

    Execute this as root:

    iptables -A INPUT -p tcp --dport 80 -j ACCEPT
    iptables -t nat -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
    iptables -A INPUT -p tcp --dport 443 -j ACCEPT
    iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8181
    

    Need to make this permanent:

    iptables-save -c > /etc/iptables.rules
    iptables-restore < /etc/iptables.rules
    

    and call during startup, vi /etc/network/if-pre-up.d/iptablesload

    #!/bin/sh
    iptables-restore < /etc/iptables.rules
    exit 0