‍WildFly is a powerful open-source Java application server developed by RedHat. It provides a fast and stable runtime environment for developing and deploying Java applications. In this tutorial, we will guide you through the process of installing WildFly on Rocky Linux 8 and setting up Nginx as a reverse proxy to access WildFly.

Prerequisites

Before we begin, make sure you have the following:

  • A server running Rocky Linux 8
  • Root access to the server

Step 1: Install Java

WildFly is a Java-based application, so we need to install Java on our server. To install Java 11, run the following command:

dnf install java-11-openjdk-devel -y

After the installation is complete, verify the installed version of Java by running:

java --version

You should see an output similar to this:

openjdk 11.0.8 2020-07-14 LTS
OpenJDK Runtime Environment 18.9 (build 11.0.8+10-LTS)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.8+10-LTS, mixed mode, sharing)

Step 2: Install WildFly

Now that we have Java installed, let’s proceed with the installation of WildFly. Before we begin, let’s create a separate user and group to run WildFly. Run the following commands to create the user and group:

groupadd --system wildfly
useradd -s /sbin/nologin --system -d /opt/wildfly -g wildfly wildfly

Next, download the latest version of WildFly from the official website. At the time of writing this tutorial, the latest version is 20.0.1. Run the following command to download WildFly:

wget https://download.jboss.org/wildfly/20.0.1.Final/wildfly-20.0.1.Final.tar.gz

Once the download is complete, extract the downloaded file using the following command:

tar -xvzf wildfly-20.0.1.Final.tar.gz

Move the extracted directory to the /opt directory:

mv wildfly-20.0.1.Final /opt/wildfly

Next, create a directory to store WildFly configuration files:

mkdir /etc/wildfly

Copy the necessary files to the desired locations:

cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/
cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/

Give proper ownership and permissions to the WildFly directory and files:

chmod +x /opt/wildfly/bin/launch.sh
chown -R wildfly:wildfly /opt/wildfly
chmod -R +x /opt/wildfly/

Reload the systemd daemon to apply the changes:

systemctl daemon-reload

Start the WildFly service and enable it to start at boot:

systemctl start wildfly
systemctl enable wildfly

Verify the status of the WildFly service:

systemctl status wildfly

You should see an output similar to this:

wildfly.service - The WildFly Application Server
Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2020-09-13 05:57:22 EDT; 16s ago
Main PID: 31834 (launch.sh)
Tasks: 123 (limit: 12527)
Memory: 304.1M
CGroup: /system.slice/wildfly.service
├─31834 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 0.0.0.0
├─31835 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0
└─31925 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=tru>

At this point, WildFly is installed and running on your server. By default, WildFly listens on port 8080. You can verify this by running the following command:

ss -tunelp | grep 8080

You should see an output similar to this:

tcp    LISTEN     0      128             0.0.0.0:8080            0.0.0.0:*      users:(("java",pid=31925,fd=478)) uid:989 ino:59014 sk:9

The WildFly admin console listens on port 9990. You can verify this by running the following command:

ss -tunelp | grep 9990

You should see an output similar to this:

tcp LISTEN 0 50 127.0.0.1:9990 0.0.0.0:* users:(("java",pid=31925,fd=138)) uid:989 ino:59017 sk:7

Step 3: Add WildFly Admin User

To access the WildFly administration console, you need to create an administrative user. Run the following command to create a management user:

/opt/wildfly/bin/add-user.sh

You will be prompted to choose the type of user to add. Select a for management user. Enter a username for the user, such as admin, and provide a password.

Next, you need to configure the firewall and SELinux for WildFly.

Step 4: Configure Firewall and SELinux

By default, SELinux is enabled on Rocky Linux 8. We need to configure SELinux to allow WildFly to run properly. Run the following commands to configure SELinux:

semanage fcontext -a -t bin_t "/opt/wildfly/bin(/.*)?"
restorecon -Rv /opt/wildfly/bin
setsebool -P httpd_can_network_connect 1

Next, we need to allow incoming connections on ports 8080, 9990, and 80. Run the following commands to open the necessary ports:

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --permanent --add-port=9990/tcp
firewall-cmd --permanent --add-port=80/tcp

Reload the firewall to apply the changes:

firewall-cmd --reload

Now that the firewall and SELinux are configured, we can proceed to access the WildFly admin console.

Step 5: Access WildFly Admin Console

By default, the WildFly admin console is only accessible from the localhost. To enable external access, we need to make some changes to the launch.sh file. Run the following command to open the file for editing:

nano /opt/wildfly/bin/launch.sh

Find the following line:

$WILDFLY_HOME/bin/standalone.sh -c $2 -b $3

Replace it with the following line:

$WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -bmanagement=0.0.0.0

Save and close the file. Restart the WildFly service to apply the changes:

systemctl restart wildfly

Now, you can access the WildFly admin console using your server’s IP address and port 9990. Open your web browser and enter the following URL:

http://your-server-ip:9990

You will be prompted to enter the username and password you created earlier. Once logged in, you will see the WildFly admin dashboard.

Step 6: Configure Nginx as a Reverse Proxy for WildFly

By default, WildFly is accessible on port 8080. To access WildFly using the standard HTTP port 80, we can configure Nginx as a reverse proxy. First, install Nginx on your server:

dnf install nginx -y

Once installed, create a new configuration file for WildFly:

nano /etc/nginx/conf.d/wildfly.conf

Add the following configuration to the file:

upstream wildfly {
server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5;
}

server {
listen 80;
server_name your-server-ip;

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://wildfly/;
}
}

Save and close the file. Check the Nginx configuration for any errors:

nginx -t

If there are no errors, start Nginx and enable it to start automatically at boot:

systemctl start nginx
systemctl enable nginx

You can check the status of the Nginx service with the following command:

systemctl status nginx

Now, you can access your WildFly application using the URL http://your-server-ip. Nginx will act as a reverse proxy and forward requests to WildFly running on port 8080.

Conclusion

Congratulations! You have successfully installed WildFly on Rocky Linux 8 and set up Nginx as a reverse proxy. This setup allows you to access your Java applications on the standard HTTP port 80. You can now start building and deploying your Java applications using the powerful features of WildFly. For reliable and scalable hosting solutions, consider Shape.host, a trusted provider of Linux SSD VPS.