Wildfly is a simple, lightweight, and flexible application runtime used to build Java applications. It is written in Java and can run on Linux, macOS, and Windows operating systems. It is an enterprise and fully featured application server that provides all the necessary features to run a Java web application.
- Free and open-source
- Modular and lightweight.
- Save resources with efficient management.
- Save time with faster development.
This tutorial will show you how to install Wildfly with Nginx as a reverse proxy on Ubuntu 22.04.
- A server running Ubuntu 22.04.
- A valid domain name is pointed to your server IP.
- A root password is configured on your server.
Update the System
First, you will need to update all of your system packages to the updated version. You can update all of them by running the following command.
apt update -y apt upgrade -y
Once all the packages are updated, you can proceed to the next step.
Install Java JDK
Wildfly is a Java-based application. So you will need to install Java on your server. You can install Java JDK with the following command.
apt install default-jdk -y
Once Java is installed, you can verify the Java version using the following command.
You should see the Java version in the following output.
openjdk 11.0.17 2022-10-18 OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04) OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)
Download and Install Wildfly
Before starting, you will need to create a dedicated user and group to run Wildfly. You can create both 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 following command.
Once the download is completed, unzip the downloaded file with the following command.
Next, move the extracted Wildfly directory to /opt directory.
mv wildfly-26.1.3.Final /opt/wildfly
Next, change the ownership of the Wildfly directory using the following command.
chown -RH wildfly: /opt/wildfly
Once you are done, you can proceed to configure Wildfly.
First, create a Wildfly configuration directory using the following command.
mkdir -p /etc/wildfly
Next, copy the Wildfly configuration file to the /etc/wildfly directory.
cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/
Next, copy the Wildfly service file to the systemd directory.
cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/
Next, copy the Wildfly launch.sh file to the /opt/wildfly/bin/ directory.
cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/
Next, set the executable permission to the script file.
chmod +x /opt/wildfly/bin/*.sh
Then, reload the systemd daemon to apply the changes.
Next, start the wildfly service and add it to the system boot.
systemctl start wildfly systemctl enable wildfly
You can now verify the status of Wildfly using 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 Wed 2023-02-15 09:34:24 UTC; 4s ago Main PID: 20425 (launch.sh) Tasks: 61 (limit: 4579) Memory: 111.6M CPU: 6.919s CGroup: /system.slice/wildfly.service ??20425 /bin/bash /opt/wildfly/bin/launch.sh standalone standalone.xml 0.0.0.0 ??20426 /bin/sh /opt/wildfly/bin/standalone.sh -c standalone.xml -b 0.0.0.0 ??20534 java "-D[Standalone]" -server -Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stac> Feb 15 09:34:24 ubuntu2204 systemd: Started The WildFly Application Server.
By default, Wildfly listens on ports 8080 and 9990. You can check them with the following command.
ss -antpl | grep -i java
You should see the following output.
LISTEN 0 4096 0.0.0.0:8443 0.0.0.0:* users:(("java",pid=20534,fd=498)) LISTEN 0 50 127.0.0.1:9990 0.0.0.0:* users:(("java",pid=20534,fd=497)) LISTEN 0 4096 0.0.0.0:8080 0.0.0.0:* users:(("java",pid=20534,fd=495))
Configure Wildfly Admin Console
By default, the Wildfly admin console is disabled. So you will need to enable it to access Wildfly from the web browser.
First, edit the Wildfly configuration file using the following command.
Change the following lines.
Save and close the file when you are done. Then, edit the launch.sh file with the following command.
Modify the following lines:
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 service file.
Modify 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 changes.
Now, restart the Wildfly service to implement the changes.
systemctl restart wildfly
Add Wildfly Administrative User
Next, you will need to add an admin user to access the Wildfly admin console. You can add it with the following command.
You will be asked for the type of user you want to add:
What type of user do you wish to add? a) Management User (mgmt-users.properties) b) Application User (application-users.properties) (a): a
Provide your new user details as shown below:
Using the realm 'ManagementRealm' as discovered from the existing property files. Username : wadmin 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 :
You will be asked to what group you want this user to belong to:
What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[ ]:
Just press the enter key. You should see the following output.
About to add user 'wadmin' for realm 'ManagementRealm' Is this correct yes/no? yes Added user 'wadmin' to file '/opt/wildfly/standalone/configuration/mgmt-users.properties' Added user 'wadmin' to file '/opt/wildfly/domain/configuration/mgmt-users.properties' Added user 'wadmin' with groups to file '/opt/wildfly/standalone/configuration/mgmt-groups.properties' Added user 'wadmin' 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 EJB calls. yes/no? yes To represent the user add the following to the server-identities definition
Configure Nginx for Wildfly
At this point, Wildfly is installed and configured to run on localhost. Now, you will need to configure Nginx as a reverse proxy to access the Wildfly web interface.
First, install the Nginx package using the following command.
apt install nginx -y
Next, create a proxy_headers configuration file.
Add the following configurations:
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 a new virtual host configuration file.
Add the following configurations.
server listen 80; server_name wildfly.example.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 the file then verify the Nginx for any syntax configuration error.
If everything is fine, you will get 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 implement the changes.
systemctl restart nginx
You can verify the status of the Nginx service with the following command.
systemctl status nginx
You should see 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 Wed 2023-02-15 09:38:18 UTC; 1s ago Docs: man:nginx(8) Process: 21027 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 21028 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS) Main PID: 21029 (nginx) Tasks: 3 (limit: 4579) Memory: 3.4M CPU: 62ms CGroup: /system.slice/nginx.service ??21029 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;" ??21030 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ??21031 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Feb 15 09:38:18 ubuntu2204 systemd: Starting A high performance web server and a reverse proxy server... Feb 15 09:38:18 ubuntu2204 systemd: Started A high performance web server and a reverse proxy server.
Access Wildfly Admin Interface
Now, open your web browser and access the Wildfly admin interface using the URL http://wildfly.example.com/console.
Provide your admin username, password then click on the Sign in button.
You can also access the Wildfly default page using the URL http://wildfly.example.com.
Congratulations! you have successfully installed Wildfly with Nginx as a reverse proxy on Ubuntu 22.04 server. You can now start building an amazing application using the Wildfly platform. Feel free to ask me if you have any questions.