How to Install GlassFish Application Server with Nginx Reverse Proxy on Debian 12
GlassFish is a free and open-source implementation of the Java EE Platform developed by Eclipse. It's the world's first implementation of the Java EE platform provides a lightweight application server and allows you to deploy multiple Java-based applications. GlassFish supports multiple types of Java-application technologies such as Enterprise JavaBeans, JPA, JavaServer Faces, JMS, and many more.
GlassFish is one of the best choices for developers to develop and deploy Java-based applications. It allows developers to develop enterprise applications in a convenient way and also scalable architecture. The GlasshFish project was originally started by Sun Microsystem. It comes with two different free Licenses - The Common Development and Distribution License and the GNU General Public License.
In this guide, you will install GlassFish Application Server on Debian 12 in a step-by-step process. You will also configure Nginx as a reverse proxy for your GlassFish installation.
Prerequisistes
To begin the process, ensure you have the following:
- A Debian 12 server with at least 4GB of RAM or memory.
- A non-root user with sudo privileges.
Installing Java OpenJDK
GlassiFish is an application server for deploying Java applications. To install GlassFish, you must install Java first on your Debian system. At this time, the Debian repository provides Java OpenJDK 17, which is compatible with the latest version of GlassFish.
First, update and refresh your Debian repository using the following command.
sudo apt update
Once the repository is updated, install the default-jdk package by executing the command below. By installing the default-jdk package, you will install Java OpenJDK 17.
sudo apt install default-jdk
Type y to proceed with the installation.
After the installation is finished, verify your Java version using the command below. You should see the Java OpenJDK 17 is installed.
java -version
Setting Up System
After installing Java OpenJDK, the next step is to set up your Debian system by installing additional packages such as wget and unzip, creating a new glassfish system user, and configuring the JAVA_HOME environment variable.
To start, you will install the unzip and wget package by executing the following apt command.
sudo apt install unzip wget -y
Now, run the command below to create a new system user glassfish. This user will be used to run your GlasFish installation, which will be located in the /opt/glassfish directory.
sudo useradd -M -d /opt/glassfish -U -s /bin/false glassfish
Next, create a new bash script /etc/profile.d/java.sh using the following nano editor command.
sudo nano /etc/profile.d/java.sh
Add the following configuration to set up the JAVA_HOME environment variable and add the Java binary path to the system PATH.
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
Save and close the file when you're done.
Now load the new environment variable within /etc/profile.d/java.sh using the source command below.
source /etc/profile.d/java.sh
Lastly, execute the following command to verify the system PATH and JAVA_HOME environment variables.
echo $JAVA_HOME
echo $PATH
If everything goes well, you should see the JAVA_HOME path is configured to the directory /usr/lib/jvm/java-17-openjdk-amd64, and the Java bin directory is added to the system PATH.
Downloading GlassFish Binary Package
With the Java OpenJDK installed and your Debian system ready, you can now download and install GlassFish. Before going further, check the GlassFish download page to get the latest version of GlassFish. At this time, the latest version of GlassFish is v7.0.10.
Go to the /tmp directory and download the GlassFish binary package via the wget command below. Once the download process is finished, you should see the file glassfish-7.0.10.zip.
cd /tmp
wget https://download.eclipse.org/ee4j/glassfish/glassfish-7.0.10.zip
Extract the glassfish-7.0.10.zip file to the /opt directory via the unzip command below. The GlassFish package will be extracted to the /opt/glassfish7 directory.
unzip glassfish-7.0.10.zip -d /opt
Lastly, rename the extracted directory from /opt/glassfish7 to /opt/glassfish. Then, change the ownership of the /opt/glassfish directory to user glassfish.
mv /opt/glassfish7 /opt/glassfish
sudo chown -R glassfish:glassfish /opt/glassfish
Running GlassFish as a Systemd Service
After downloading GlassFish binary package, you will be creating a new systemd service file that will be used to run GlassFish. This allows you to manage GlassFish via the systemctl utility and run GlassFish in the background as a systemd service.
To run GlassFish as a systemd service, run the below nano editor command to create a new file /etc/systemd/system/glassfish.service.
sudo nano /etc/systemd/system/glassfish.service
Insert the following configuration into the file.
[Unit]
Description = GlassFish Server v7
After = syslog.target network.target
[Service]
User=glassfish
ExecStart=/opt/glassfish/bin/asadmin start-domain
ExecReload=/opt/glassfish/bin/asadmin restart-domain
ExecStop=/opt/glassfish/bin/asadmin stop-domain
Type = forking
[Install]
WantedBy = multi-user.target
Save and close the when you're done.
Now, run the following systemctl command to reload the systemd manager and apply the changes.
sudo systemctl daemon-reload
With the systemd manager reloaded, start and enable the glassfish service using the following command.
sudo systemctl start glassfish
sudo systemctl enable glassfish
Lastly, verify the glassfish service status using the command below.
sudo systemctl status glassfish
If everything goes well, you should see the glassfish status as active (running), and it is enabled.
Setting up User and Securing GlassFish Administration
At this point, GlassFish is up and running. Now you will configure GlassFish installation by changing the default password for Admin Console and enable the Secure Admin. These can be done via the asadmin command that is available in the /opt/glassfish/bin directory.
Execute the asadmin command line below to change the admin password for your GlassFish installation.
sudo -u glassfish /opt/glassfish/bin/asadmin --port 4848 change-admin-password
During the process, you will be asked the following:
- Input the default admin user for GlassFish.
- Press ENTER when asked for the password. The default admin user for GlassFish comes without a password.
- Now input the new admin password for GlassFish and repeat.
When the process is complete, you should get the message like the following:
Next, run the asadmin command below to enable secure admin on your GlassFish installation.
Essentially, the Secure Admin enables secure communications via SSL between the domain administration server (DAS), remote instances, and administration clients, including the asadmin utility, the administration console, and REST clients.
sudo -u glassfish /opt/glassfish/bin/asadmin --port 4848 enable-secure-admin
Enter your GlassFish admin user and password, then press Enter. When finished, the following output will be displayed.
After the Secure admin is enabled, run the following command to restart the glassfish service and apply the changes.
sudo systemctl restart glassfish
Now, launch your web browser and visit the server IP address followed by port 8080 such as http://192.168.5.15:8080/. If your GlassFish installation is successful, you should get the following page, which confirms that GlassFish is running.
Lastly, open a new tab and visit the same server IP address with port 4848 (i.e: https://192.168.5.15:4848/) to access the GlassFish administration page. Accept the SSL/TLS certificates on your web browser, and if successful, you should get the GlassFish administration login page below.
Installing Nginx as a Reverse Proxy
In this guide, you will run GlassFish with Nginx as a reverse proxy. Now, you will install Nginx on your Debian machine and create a new server block configuration for GLassFish. In this case, we'll be using a local domain name glassfish.howtoforge.local.
First, install Nginx to your Debian system using the following apt command. Input y to proceed with the installation.
sudo apt install nginx
After Nginx is installed, create a new server block configuration /etc/nginx/sites-available/glassfish using the following nano editor command.
sudo nano /etc/nginx/sites-available/glassfish
Insert the following configuration and be sure to change the server_name parameter with your local domain name.
upstream glassfish {
server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5;
}
server {
listen 80;
server_name glassfish.howtoforge.local;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://glassfish/;
}
}
Save and exit the file when finished.
Next, run the following command to activate the server block configuration glassfish and verify Nginx syntax to ensure that you've proper syntax.
sudo ln -s /etc/nginx/sites-available/glassfish /etc/nginx/sites-enabled/
sudo nginx -t
If you have the correct Nginx syntax, you should get the output 'test is successful - syntax is ok'.
Now you can restart the Nginx service and apply the changes. Then, verify the Nginx service to ensure that the service is running.
sudo systemctl restart nginx
sudo systemctl status nginx
In the following output, you should see the Nginx service is running.
Accessing GlassFish Installation
In the last section, you will access your GlassFish installation from the client machine. You can use any operating system as your client machine.
Edit the /etc/hosts file on your local machine and insert the following configuration. Be sure to change the server IP address and the local domain name. If you're using a Windows client, be sure to modify the C:\Windows\System32\drivers\etc\hosts file as an administrator.
192.168.5.15 glassfish.howtoforge.local
Now back to your web browser and visit the domain name of your GlassFish installation, such as http://glassfish.howtoforge.local/. If your Nginx reverse proxy configuration is successful, you should see the default GlassFish page index page like the following.
Next, visit the GlassFish administration page within port 4848 (i.e: https://glassfish.howtoforge.local:4848/). Within the login page, input your admin user and password, then click Login.
If your installation is successful, you should get the GlassFish administration dashboard like the following:
Now click on the Server menu to check the status of your GlassFish installation. In this example, you should see that GlassFish 7.0 is installed with the status Running.
From here, you can now manage your GlassFish application server
Conclusion
In conclusion, you have now successfully installed the GlassFish Application Server on a Debian 12 server, following the step-by-step instructions. You've installed GlassFish with Java OpenJDK 17 and Nginx as a reverse proxy, and also secured GlassFish by changing the default admin password and enabling the Secure Admin. You can now start deploying your application with GlassFish.