30

Did some google on it and the solution was to redirect using iptables or mod in apache? Since my application uses websockets the above solution breaks my websocket connectivity and I again have to connect to my websockets using port 8080. Is there any way that I can run the glassfish itself on port 80 so that my websockets also run on port 80 making easier for users behind corporate firewall to access the app since corparates may block 8080.

I have root access as well.

Cœur
  • 37,241
  • 25
  • 195
  • 267
anandaravindan
  • 2,401
  • 6
  • 25
  • 35

6 Answers6

61

To run GlassFish on port 80 you need to :

  1. Connect to the administration interface (by default on port :4848)

  2. In the left menu go to Configurations

  3. Then select the appropriate configuration you need to change eg server-config

  4. Then go to Network Config

  5. Then go to Network Listeners

  6. Select the appropriate listener, probably http-listener-1

  7. Change the Port value to 80

  8. Save and reboot your GlassFish server/instance/cluster according to your needs

Using the command line utility

asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.port=80 

you may need to replace server-config and/or http-listener-1

Matt
  • 45,022
  • 8
  • 78
  • 119
Alexandre Jacob
  • 2,993
  • 3
  • 26
  • 36
  • 6
    Yes of course, `asadmin set configs.config.server-config.network-config.network-listeners.network-listener.http-listener-1.port=80` you may need to replace `server-config` and/or `http-listener-1` – Alexandre Jacob Aug 06 '13 at 23:26
  • changing the port shouldn't cause Glassfish to fail to start, should it? That's unrelated? – Thufir Nov 02 '14 at 09:12
  • 5
    It should not be related but keep in mind that on unix system you can't listen on a port lower than 1024 if you are not root. In this case you'll probably get a *SocketException: Permission denied* – Alexandre Jacob Nov 02 '14 at 14:05
  • Or you could create new listener instead of changing existing one. Depends, what you want/need. – Dainius Oct 04 '15 at 11:49
  • In Linus Systems, how can we do this? Can we run GlassFish as root? – Buddhika Ariyaratne Nov 09 '19 at 00:16
35

Go to glassfish4\glassfish\domains\domain1\config folder and here open domain.xml file and find tag

<network-listeners>
    <network-listener port="9999" protocol="http-listener-1" transport="tcp" name="http-listener-1" thread-pool="http-thread-pool"></network-listener>
</network-listeners>

in port attribute of <network-listeners> you can specify your port address whichever you want.

shinjin
  • 2,858
  • 5
  • 29
  • 44
mukul anand
  • 351
  • 3
  • 2
3

Here's another approach.

You can go to the admin console under port 4848 (I am using Glassfish 4.1.2) and navigate to "Configuration" > "server-config" > "HTTP Service" > "Http Listeners" > "http-listener-1" in the left hand navigation.

Click on the "http-listener-1" link in the main content window.

Change the port to desired number and save.

enter image description here

Restart Glassfish and run your application.

enter image description here

BustedSanta
  • 1,368
  • 7
  • 28
  • 55
2

in some cases you have to change port before glassfish is started (in my case port 8080 is already in use by another instance) so answer 4 worked for me.

pikimota
  • 241
  • 1
  • 4
  • 15
1

Two Option :

One that I use , Is in create domain in asadmin call this command : Found here Oracle Docs

create-domain  --instanceport 80 --domainproperties http.ssl.port=443  yourdomainname

change yourdomainname with yours , the output is :


Using default port 4848 for Admin.
Using port 80 for HTTP Instance.
Using default port 7676 for JMS.
Using default port 3700 for IIOP.
Using port 443 for HTTP_SSL.
Using default port 3820 for IIOP_SSL.
Using default port 3920 for IIOP_MUTUALAUTH.
Using default port 8686 for JMX_ADMIN.
Using default port 6666 for OSGI_SHELL.
Using default port 9009 for JAVA_DEBUGGER.

The http port and https port change it! in this way I don't need go for security admin !(I do it later)

The option Two : is use Network Config that already answerd on top.

0

Following are simple steps to change the port number of Glassfish server
(GlassFish runs by default on port number 8080):

  1. Go to the folder where Glassfish is installed.
  2. Locate config folder which is as follows (Windows):
    • C:\Program Files\glassfish-3.0.1\glassfish\domains\domain1\config
  3. Open domain.xml using any text editor.
  4. Look for 8080 and change it to some other port number that doesn’t conflict with other port numbers (e.g. 8081).
  5. Save domain.xml.

Additional step if necessary:

  1. Now remove GlassFish from IDE and add it again so that IDE understands the new port number.
  2. Restart GlassFish, if it was already running.

Soruce Link

Mehdi Rahimi
  • 1,453
  • 5
  • 20
  • 31