GlassFish is a powerful open-source application server that allows you to deploy and manage Java applications. With its support for various Java-based technologies, GlassFish provides developers with a versatile platform for building scalable and portable applications. In this tutorial, we will guide you through the process of installing GlassFish on Debian 11 and configuring Nginx as a reverse proxy to enhance its performance and security.
Prerequisites
Before we begin, make sure you have the following:
- A server running Debian 11.
- A valid domain name pointed to your server’s IP address.
- A root password configured on the server.
Step 1: Install Java
Since GlassFish is a Java-based application, you need to have Java installed on your server. If you don’t have Java installed, you can install it by running the following command:
apt-get installdefault-jdk unzip -y
To verify the Java installation, use the following command:
java --version
You should see the version information for Java displayed.
Step 2: Download GlassFish
Next, you need to download the latest version of GlassFish from the Eclipse website. You can use the wget
command to download the file. For example:
wget https://download.eclipse.org/ee4j/glassfish/glassfish-6.1.0.zip
Once the download is complete, extract the downloaded file to the /opt
directory:
unzip glassfish-6.1.0.zip -d /opt/
Step 3: Create a Systemd Service File for GlassFish
To manage the GlassFish service, you need to create a systemd service file. Open a text editor and create the file:
nano /usr/lib/systemd/system/glassfish.service
Add the following content to the file:
[Unit]
Description = GlassFish Server v6.1.0
After = syslog.target network.target
[Service]
User = root
ExecStart = /usr/bin/java -jar /opt/glassfish6/glassfish/lib/client/appserver-cli.jar start-domain
ExecStop = /usr/bin/java -jar /opt/glassfish6/glassfish/lib/client/appserver-cli.jar stop-domain
ExecReload = /usr/bin/java -jar /opt/glassfish6/glassfish/lib/client/appserver-cli.jar restart-domain
Type = forking
[Install]
WantedBy = multi-user.target
Save and close the file. Then, reload the systemd daemon to apply the changes:
systemctl daemon-reload
Start the GlassFish service and enable it to start automatically at system boot:
systemctl start glassfish systemctl enable glassfish
To verify the status of the GlassFish service, use the following command:
systemctl status glassfish
Step 4: Set GlassFish Admin Password
By default, GlassFish is accessible without any password, which is not secure. To set an admin password, run the following command:
/opt/glassfish6/bin/asadmin --port 4848 change-admin-password
You will be prompted to enter the admin username. Use the default admin username provided:
Enter admin user name[default: admin]> admin
Press Enter when asked for the existing admin password. Then, set a new admin password when prompted:
Enter the new admin password> [Enter your password] Enter the newa dmin password again> [Enter your password again]
Once the password is set, enable HTTPS on GlassFish for added security:
/opt/glassfish6/bin/asadmin --port 4848 enable-secure-admin
Enter your admin username and password when prompted. Finally, restart the GlassFish service to apply the changes:
systemctl restart glassfish
Step 5: Access the GlassFish Web Interface
Now that GlassFish is installed and running, you can access the web interface. The GlassFish web interface listens on port 8080, while the admin interface listens on port 4848.
To access the GlassFish web interface, open a web browser and enter the following URL:
http://your-server-ip:8080
You should see the GlassFish welcome page.
To access the GlassFish admin interface, use the following URL:
https://your-server-ip:4848
You will be redirected to the GlassFish login page. Enter your admin username and password to access the admin interface.
Step 6: Configure Nginx as a Reverse Proxy for GlassFish
To enhance the performance and security of GlassFish, it is recommended to configure Nginx as a reverse proxy. This allows you to access your applications without specifying the port number.
First, install Nginx on your server:
apt-get install nginx -y
Create an Nginx virtual host configuration file:
nano /etc/nginx/conf.d/glassfish.conf
Add the following content to the file:
upstream glassfish { server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5; } server { listen 80; server_name glassfish.example.com; 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/hello/; } }
Save and close the file. Next, verify the Nginx configuration for any syntax errors:
nginx -t
If the output shows that the configuration is fine, restart the Nginx service:
systemctl restart nginx
To check the status of Nginx, use the following command:
systemctl status nginx
Conclusion
Congratulations! You have successfully installed GlassFish on Debian 11 and configured Nginx as a reverse proxy. You can now deploy your Java applications on GlassFish and access them securely through Nginx. If you have any questions or need further assistance, feel free to reach out to us at Shape.host. We provide reliable and scalable cloud hosting solutions, including Linux SSD VPS, to empower your business with efficient and secure hosting services. Happy coding!