Home / How To / How to install WildFly Java Application Server with Nginx Reverse Proxy on Ubuntu 20.04

How to install WildFly Java Application Server with Nginx Reverse Proxy on Ubuntu 20.04



WildFly or formerly known as JBoss AS is an easy implementation of the JEE container (Java Enterprise Edition). Its flexible application time is written in Java to help you build great applications.

WildFly is a runtime for multiple platforms running on Linux, macOS and Windows operating systems. Created by JBoss Inc and acquired in 2006 by RedHat and became WildFly.

In this tutorial we will show you how to install WildFly on the latest Ubuntu 20.04. We install the latest version of WildFly 20, enable the WildFly Admin Console, create the WildFly Admin User, and set up Nginx as a reverse proxy for WildFly.

Conditions

For this guide, we are installing WildFly on the latest Ubuntu Server 20.04 FocalFossa with 2 GB of RAM, 50 GB of free disk space and 2 processors.

What should we do?

  • Installing Java OpenJDK 11
  • Add new user and download WildFly
  • WildFly basic configuration
  • Enable the WildFly Admin Console
  • Set up WildFly admin users
  • Set up Nginx as a reverse proxy for WildFly
  • Testing

Step 1 – Install Java OpenJDK

First, we install Java OpenJDK on the Ubuntu server 20.04. And we will use Java OpenJDK 11 for our WildFly installation, which is the standard version of Java packages on the Ubuntu 20.04 repository.

Update all package repositories and install Java OpenJDK using the apt command below.

sudo apt update
sudo apt install default-jdk

When all the installation is complete, check the Java version with the following command.

java -version

Below is the result you get.

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

As a result, the installation of Java OpenJDK on Ubuntu 20.04 has been completed.

Step 2 – Add new user and download WildFly

In this step, we create a new system user and group ‘wildfly’ and download the source code for wildfly to the directory ‘/ opt / wildfly’.

Now create a new user and group named ‘wildfly’ using the commands below.

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

Then go to the directory ‘/ opt’ and download the source code for wildfly using the wget command as below.

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

The Wildfly source code has been downloaded.

Now extract the source code for wildfly and rename the extracted directory to ‘wildfly’.

tar -xf wildfly-20.0.1.Final.tar.gz
mv wildfly-20.0.1.Final wildfly

Then change the ownership of the “wildfly” directory to the “wildfly” user and the group.

chown -RH wildfly:wildfly /opt/wildfly

As a result, the wildfly installation directory is located in the ‘/ opt / wildfly’ directory. The Wildfly service is run under the new user name ‘wildfly’ which we just created on top.

Create new user and download the WildFly source code

Step 3 – WildFly basic configuration

After downloading the wildfly source code, we will set up wildfly on the Ubuntu system.

Create new configuration directory ‘/ etc / wildfly’ and copy the sample configuration ‘wildfly.conf’ to it.

mkdir -p /etc/wildfly
cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.conf /etc/wildfly/

Then copy the service file ‘wildfly.service’ to the directory ‘/ etc / systemd / system’.

cp /opt/wildfly/docs/contrib/scripts/systemd/wildfly.service /etc/systemd/system/

Then copy the example of the wildfly launch script to the directory ‘/ opt / wildfly / bin’ and make it executable.

cp /opt/wildfly/docs/contrib/scripts/systemd/launch.sh /opt/wildfly/bin/
chmod +x /opt/wildfly/bin/*.sh

Now reload the systemd manager to apply the new ‘wildfly.service’ file.

systemctl daemon-reload

Start the wildfly service and add it to system boot.Advertisement

systemctl start wildfly
systemctl enable wildfly

The Wildfly service is running on the Ubuntu system with the default configuration.

WildFly basic configuration

Check the wildfly service with the following command.

ss -plnt
systemctl status wildfly

And you get the result as below.

Launch WildFly as a Systemd service

WildFly control port

As can be seen, wildfly runs as a systemd service on the standard TCP port ‘8080’ on the Ubuntu system.

Step 4 – Activate the WildFly Admin Console

In this step, we will set up a wildfly to run on the local IP address ‘127.0.0.1’ and activate its admin console. We will edit the wildfly configuration ‘wildfly.conf’, the wildfly startup script ‘launch.sh’ and the wildfly service file ‘wildfly.service’.

Edit the wildfly configuration ‘/etc/wildfly/wildfly.conf’ with vim editor.

vim /etc/wildfly/wildfly.conf

Now change the value of ‘WILDFLY_BIND’ with the local IP address ‘127.0.0.1’.Advertisement

WILDFLY_BIND=127.0.0.1

To enable the Wildfly Admin Console, add the ‘WILDFLY_CONSOLE_BIND’ configuration below.

WILDFLY_CONSOLE_BIND=127.0.0.1

Save and close.

Then edit the wildfly startup script ‘/opt/wildfly/bin/launch.sh’ using vim-editor.

vim /opt/wildfly/bin/launch.sh

On ‘domain.sh‘and’independent.shrows, add additional options to activate the Wildfly Admin Console 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.

Then edit the default wildfly service file ‘/etc/systemd/system/wildfly.service’ using vim-editor.

vim /etc/systemd/system/wildfly.service

On ‘ExecStart = / opt / wildfly / bin / launch.sh ….‘line, add option’$ WILDFLY_CONSOLE_BIND‘as below.

ExecStart=/opt/wildfly/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND $WILDFLY_CONSOLE_BIND

Save and close.

Now reload the systemd manager and restart the wildfly service.

systemctl daemon-reload
systemctl restart wildfly

WildFly Enable Admin Console

The Wildfly service runs with the administrator console activated, check with the command below.

ss -plnt
systemctl status wildfly

Below is the result you get.

WildFly Check port and service

As a result, wildfly runs at the local IP address’127.0.0.1‘with standard TCP port’8080‘, and the wildfly admin console enabled on TCP port’9990‘.

Step 5 – Configure WildFly Administrator Users

In this step, we create a new user for managing wildfly with the script ‘add-user.sh’ from wildfly.

Run the script ‘add-user.sh’ by wildfly as below.

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

For type of user, type ‘a‘to create the management user (admin for managing wildfly).

What type of user do you wish to add? 
 a) Management User (mgmt-users.properties)
 b) Application User (application-users.properties)
(a): a

Now enter your username and password and make sure you use the secure password.

Enter the details of the new user to add.
Using the realm 'ManagementRealm' as discovered from the existing property files.
Username : hakase
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 :

For the group of the new user, just press’Get on‘ continue.

What groups do you want this user to belong to? (Please enter a comma separated list, or leave blank for none)[  ]:

Then write ‘yes‘to add your user to’ManagementRealmon wild fly.

About to add user 'hakase' for realm 'ManagementRealm'
Is this correct yes/no? yes
Added user 'hakase' to file '/opt/wildfly/standalone/configuration/mgmt-users.properties'
Added user 'hakase' to file '/opt/wildfly/domain/configuration/mgmt-users.properties'
Added user 'hakase' with groups  to file '/opt/wildfly/standalone/configuration/mgmt-groups.properties'
Added user 'hakase' with groups  to file '/opt/wildfly/domain/configuration/mgmt-groups.properties'

Write ‘yes‘to activate your user as a process for managing the master-slave host controller for wildfly.

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

As a result, the admin and management user for wildfly has been created.Advertisement

Step 6 – Configure Nginx as a reverse proxy for WildFly

In this step, we will install and configure Nginx as a reverse wildfly proxy on the Ubuntu system.

Install Nginx packages using the apt command below.

sudo apt install nginx -y

When all installation is complete, go to the configuration directory ‘/ etc / nginx /’.

cd /etc/nginx/

Create a new file ‘proxy_headers.conf’ under the directory ‘/etc/nginx/conf.d’ with vim-editor.

vim conf.d/proxy_headers.conf

Paste the following configuration.

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.

Then create a new virtual host configuration for wildfly under the directory ‘/ etc / nginx / sites-available’.

vim sites-available/wildfly

Change the IP address with your own and paste the configuration into it.

server {
  listen          80;
  server_name     SERVER-IP;

  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.

Next, enable the wildfly virtual host and check the Nginx configuration.

ln -s /etc/nginx/sites-available/wildfly /etc/nginx/sites-enabled/
nginx -t

Now make sure there is nothing wrong and then restart the Nginx service.

systemctl restart nginx

As a result, the Nginx installation and configuration of a wildfly reverse proxy has been completed.

set up Nginx as a reverse proxy for WildFly

Step 7 – Testing

Open your browser and enter the server’s IP address in the address bar.

http://192.168.1.50/

Now you get the default index page for wildfly as below.

WildFly default index

Then go to the wildfly admin console on the ‘/ console’ URL path as shown below.

http://192.168.1.50/console/

Log in with your wildfly admin user and password.

WildFly Login Administrator

Now you get the wildfly admin dashboard as below.

WildFly Admin Console Dashboard

As a result, the installation of wildfly with Nginx reverse proxy on Ubuntu 20.04 Server has been successfully completed.


Source link