How to Install and Configure WildFly (JBoss) on Debian 11
Wildfly is an application server written in Java and developed by RedHat. It is a simple, lightweight, and powerful server with a CLI and an admin console. It is open-source, cross-platform, and based on pluggable subsystems that can be added or removed as needed. It provides all the necessary features to run a Java web application.
In this tutorial, I will show you how to install Wildfly with Nginx as a reverse proxy on Debian 11.
Prerequisites
- A server running Debian 11.
- A valid domain name pointed with your server IP.
- A root password is configured on your server.
Install Java JDK
Wildfly is a Java-based application so Java must be installed on your server. If not installed, you can install it by running the following command:
apt-get install default-jdk -y
Once Java is installed, you can verify it using the following command:
java --version
You should see the Java version in the following output:
openjdk 11.0.12 2021-07-20 OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2deb10u1) OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2deb10u1, mixed mode, sharing)
Install Wildfly
First, create a user and group to run the Wildfly application using the following command:
groupadd -r wildfly
useradd -r -g wildfly -d /opt/wildfly -s /sbin/nologin wildfly
Next, download the latest version of Wildfly using the wget command:
wget https://github.com/wildfly/wildfly/releases/download/25.0.1.Final/wildfly-25.0.1.Final.zip
Once the download is completed, unzip the downloaded file with the following command:
unzip wildfly-25.0.1.Final.zip
Next, move the extracted directory to the /opt using the following command:
mv wildfly-25.0.1.Final /opt/wildfly
Next, change the ownership of /opt/wildfly directory:
chown -RH wildfly:wildfly /opt/wildfly
Next, create a Wildfly configuration directory inside /etc using the following command:
mkdir -p /etc/wildfly
Next, copy all necessary files from the Wildfly directory to the /etc/wildfly directory:
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/
Next, set execution permission to all shell script files:
chmod +x /opt/wildfly/bin/*.sh
Next, reload the systemd daemon with the following command:
systemctl daemon-reload
Next, start and enable the Wildfly service using the following command:
systemctl start wildfly
systemctl enable wildfly
To check the Wildfly service status, run the following command:
systemctl status wildfly
You will get the following output:
? wildfly.service - The WildFly Application Server Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2021-12-10 14:55:07 UTC; 6s ago Main PID: 20928 (launch.sh) Tasks: 59 (limit: 4701) Memory: 171.6M CGroup: /system.slice/wildfly.service ??20928 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 0.0.0.0 ??20929 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0 ??21022 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=tru Dec 10 14:55:07 debian11 systemd[1]: Started The WildFly Application Server.
Enable Wildfly Admin Console
By default, the Wildfly admin console is disabled. It is recommended to enable it to manage the Wildfly application.
You can enable it by editing the Wildfly configuration file:
nano /etc/wildfly/wildfly.conf
Change the following lines:
WILDFLY_BIND=127.0.0.1 WILDFLY_CONSOLE_BIND=127.0.0.1
Save and close the file then edit the Wildfly launcher script and enable the admin console.
nano /opt/wildfly/bin/launch.sh
Change the file as shown below:
if [[ "$1" == "domain" ]]; then $WILDFLY_HOME/bin/domain.sh -c $2 -b $3 -bmanagement $4 else $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -bmanagement $4 fi
Save and close the file then edit the Wildfly systemd file:
nano /etc/systemd/system/wildfly.service
Change the following line:
ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND $WILDFLY_CONSOLE_BIND
Save and close the file then reload the systemd daemon to apply the configuration changes:
systemctl daemon-reload
Next, restart the Wildfly service to apply the changes:
systemctl restart wildfly
You can also check the status of the Wildfly with the following command:
systemctl status wildfly
You will get the following output:
? wildfly.service - The WildFly Application Server Loaded: loaded (/etc/systemd/system/wildfly.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2021-12-10 14:57:22 UTC; 3s ago Main PID: 21182 (launch.sh) Tasks: 64 (limit: 4701) Memory: 205.6M CGroup: /system.slice/wildfly.service ??21182 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 127.0.0.1 127.0.0.1 ??21183 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 127.0.0.1 -bmanagement 127.0.0.1 ??21282 java -D[Standalone] -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=tru Dec 10 14:57:22 debian11 systemd[1]: Started The WildFly Application Server.
At this point, Wildfly is started and listens on ports 8080 and 9990. You can check them with the following command:
ss -plnt
You will get the following output:
State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=678,fd=3)) LISTEN 0 128 127.0.0.1:8443 0.0.0.0:* users:(("java",pid=21282,fd=485)) LISTEN 0 50 127.0.0.1:9990 0.0.0.0:* users:(("java",pid=21282,fd=487)) LISTEN 0 80 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=12461,fd=21)) LISTEN 0 128 127.0.0.1:8080 0.0.0.0:* users:(("java",pid=21282,fd=476)) LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=678,fd=4))
Once you are finished, you can proceed to the next step.
Create Wildfly Admin User
Next, you will also need to create an admin user to access the Wildfly admin console. You can create it by running the following command:
sh /opt/wildfly/bin/add-user.sh
You will be asked to choose the types of user:
What type of user do you wish to add? a) Management User (mgmt-users.properties) b) Application User (application-users.properties) (a): a
Type a and press the Enter key to add the management user. You will be asked to define your username and password as shown below:
Enter the details of the new user to add. Using realm 'ManagementRealm' as discovered from the existing property files. Username : hitesh Password recommendations are listed below. To modify these restrictions edit the add-user.properties configuration file. - The password should be different from the username - The password should not be one of the following restricted values {root, admin, administrator} - The password should contain at least 8 characters, 1 alphabetic character(s), 1 digit(s), 1 non-alphanumeric symbol(s) Password : Re-enter Password :
Provide your username, password and press Enter. You will be asked to add users to the realm:
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[ ]: About to add user 'hitesh' for realm 'ManagementRealm' Is this correct yes/no? yes
Type yes and press the Enter key to continue. Once the user is added, you will get the following output:
Added user 'hitesh' to file '/opt/wildfly/standalone/configuration/mgmt-users.properties' Added user 'hitesh' to file '/opt/wildfly/domain/configuration/mgmt-users.properties' Added user 'hitesh' with groups to file '/opt/wildfly/standalone/configuration/mgmt-groups.properties' Added user 'hitesh' with groups to file '/opt/wildfly/domain/configuration/mgmt-groups.properties' Is this new user going to be used for one AS process to connect to another AS process? e.g. for a slave host controller connecting to the master or for a Remoting connection for server to server Jakarta Enterprise Beans calls. yes/no? yes To represent the user add the following to the server-identities definition
Once you are finished, you can proceed to the next step.
Install and Configure Nginx as a Reverse Proxy
Next, you will need to configure the Nginx as a reverse proxy to access the Wildfly through port 80.
First, install the Nginx package using the command below:
apt-get install nginx -y
Once the Nginx is installed, create an Nginx proxy file with the following command:
nano /etc/nginx/conf.d/proxy_headers.conf
Add the following lines:
proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme; add_header Front-End-Https on; add_header Cache-Control no-cache;
Save and close the file then create an Nginx virtual host configuration file for Wildfly:
nano /etc/nginx/conf.d/wildfly.conf
Add the following lines:
server { listen 80; server_name wildfly.yourdomain.com; location / { include conf.d/proxy_headers.conf; proxy_pass http://127.0.0.1:8080; } location /management { include conf.d/proxy_headers.conf; proxy_pass http://127.0.0.1:9990/management; } location /console { include conf.d/proxy_headers.conf; proxy_pass http://127.0.0.1:9990/console; } location /logout { include conf.d/proxy_headers.conf; proxy_pass http://127.0.0.1:9990/logout; } location /error { include conf.d/proxy_headers.conf; proxy_pass http://127.0.0.1:9990; } }
Save and close the file then verify the Nginx for any syntax error using the following command:
nginx -t
You should see the following output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Finally, restart the Nginx service to apply the changes:
systemctl restart nginx
You can also check the Nginx status using the command below:
systemctl status nginx
You will get the following output:
? nginx.service - A high performance web server and a reverse proxy server Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2021-12-10 15:12:26 UTC; 9s ago Docs: man:nginx(8) Process: 22115 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 22116 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 22117 (nginx) Tasks: 3 (limit: 4701) Memory: 3.8M CGroup: /system.slice/nginx.service ??22117 nginx: master process /usr/sbin/nginx -g daemon on; master_process on; ??22118 nginx: worker process ??22119 nginx: worker process Dec 10 15:12:25 debian11 systemd[1]: Starting A high performance web server and a reverse proxy server... Dec 10 15:12:26 debian11 systemd[1]: Started A high performance web server and a reverse proxy server.
At this point, Nginx is installed and configured to serve Wildfly. You can now proceed to the next step.
Access Wildfly Web UI
Now, open your web browser and access the Wildfly application page using the URL http://wildfly.yourdomain.com. You should see the Wildfly default page on the following screen:
To access the Wildfly admin console type the URL http://wildfly.yourdomain.com/console/ in your web browser. You will be asked to provide an admin username and password as shown below:
Provide your admin username, password and click on the Sign in button. Once you are logged in, you should see the Wildfly admin dashboard:
Conclusion
Congratulations! you have successfully installed Wildfly with Nginx as a reverse proxy on Debian 11. You can now use Wildfly to host your Java application on the internet. Feel free to ask me if you have any questions.