Search code examples
eclipsehttphttpsglassfishglassfish-3

How to redirect domain:port to domain with Glassfish?


I have a domain like www.example.com, I'm using Glassfish, which hosts my application at port 12544.

So I wonder two things :

  1. How can I redirect this www.example.com:12544 to www.example.com ?

  2. And the same way but for https ? I mean, https://www.example.com ?

I am really new to Glassfish any help will be very appreciated.


Solution

  • The best way is to place Glassfish behind Apache http server and configure apache to point requests to glassfish. Therefore http requests are handled by Apache and all www.example.com requests are pointed to www.example.com:12544 internally. Below is a brief explanation of how to do this.

    • Install Glassfish 3+ (make sure your listener is created and activated on 8009 and your jk is enabled)
    • Install Apache (2.2+)
    • get the mod_jk connector and place it into apache modules folder to do the configurations.
    • create a worker.properties file and place it into apache conf folder. It should contain the following properties:
        worker.list=worker1
        worker.worker1.type=ajp13
        worker.worker1.host=localhost
        worker.worker1.port=8009
    
    • Open httpd.conf file in apache conf folder and place the following commands (outside Virtual Host):
    LoadModule jk_module modules/mod_jk.so
    #location of the worker file
    JkWorkersFile conf/worker.properties
    #where to put jk logs
    JkLogFile logs/mod_jk.log
    #log level [deug/error/info]
    JkLogLevel debug
    #Log format
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
    # Indicate to send SSL KEY SIZE
    JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
    # Set the request format
    JkRequestLogFormat "%w %V %T"
    # Send all jsp requests to Glassfish
    JkMount /*.jsp worker1
    # Send all webapp requests to Glassfish
    JkMount /* worker1
    

    You need also to add a VirtualHost section in your conf file. This maps your domain with the path in Glassfish so Apache will be able to see it. The following tells apache to map all /myapp/* links to glassfish

    <VirtualHost 111.111.111.111:80>
        ServerAdmin admin@domain
        ServerName domain
        JkMount /myapp/* worker1
    </VirtualHost>
    

    Note: if your Glassfish listener is not created you can created from cmd using glassfish asadmin with the following command:

    asadmin create-network-listener --protocol http-listener-1 --listenerport 8009 --jkenabled true jk-connector
    
    • Restart Apache and Glassfish for the new configurations to be updated. Apache should now see your Glassfish on port 80. So your www.example.com:12544 will be served on www.example.com.