Search code examples
ssltomcathttpsdnshostname

How to resolve localhost:8443 to alias URL like "https://mydev.example" in my local Tomcat


I have successfully setup SSL in my local Tomcat at port 8443 with a certificate I generated locally for dev purposes. It is working fine.

In my /etc/hosts file I have entries:

127.0.0.1  mydev.example  mydevsecure.example

I can access my app by typing in: https://mydevsecure.example:8443/myApp/myPage.jsp [https] OR http://mydev.example/myApp/myPage.jsp [http]

What I want is to be able to type: https://mydevsecure.example/myApp/myPage.jsp

I want to lose typing the port number 8443 in my browser.

I can't specify port number in /etc/hosts file that I am aware of.

What other solutions are there?


Solution

  • I solved this by the following approach:

    Create self signed SSL certificate

    Run the OpenSSL command to generate your private key and public certificate. Answer the questions and set a password as prompted.

    openssl req -newkey rsa:2048 -nodes -keyout mykey.pem -x509 -days 365 -out mycert.pem
    

    Install Apache

    sudo yum install httpd
    

    Add SSL config in /etc/httpd/conf/httpd.conf

    <VirtualHost _default_:443>
    SSLEngine On
    SSLCertificateFile /<path_to_ssl_certificate>/mycert.pem
    SSLCertificateKeyFile /<path_to_ssl_key>/mykey.pem
    ServerName https:// mydev.example
    ServerAlias https:// mydev.example
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    </VirtualHost>
    

    Add the new secure URL alias in hosts file

    127.0.0.1 mydev.example

    Start Tomcat and Apache

    I can now access my application through secure URL:

    https://mydev.example/myApp/myPage.jsp