Welcome to another RackNerd server tutorial! In this blog post we will be covering on how to deploy Java Applications on a Ubuntu VPS server. We will additionally cover step by step instructions on how to configure a domain name for the application running on a custom port.

Without further ado, let’s get started!

STEP #1: Login to your Ubuntu based VPS server via SSH. Please ensure that you have root privileges.

STEP #2: Prerequisites for running the java application

This sample application is built on java 8, so we need to have java 8 installed on our server via the below commands:

yum install java-1.8.0-openjdk

yum install -y git

We are using as our repo to store the code.

STEP #3: Create a directory and clone to repo

Example: mkdir racknerdjava

cd racknerdjava

git clone https://github.com/xxxy/xxxy – replace this with your repo name.

If you don’t have a repo that’s fine, you can upload the jar file and other dependency directly to the server via FTP or using any tool of your choice.

STEP #4: Now we have our jar file, lets run our java application

java -jar jarfileofyourapplication

Next, load the application at: http://serverip:port

Now we have got our application running but when we exit the shell the application stops, to make sure the application runs even of the terminal session is ended let us following command.

nohup java -jar jarfileofyourapplication

and press Enter twice

You can see the application process running by command

ps -ef | grep java

Now we that our application running via custom port, we need to configure our application to run via Domain name. To do that, we will be using Ngnix websever and loading our application via proxy.

STEP #5: Install Ngnix

Run the below commands to install Ngnix on your VPS server and start the service

sudo apt-get install nginx -y

service nginx status

service nginx start

STEP #6: Configure the Nginx to load your Java application running on custom port to load via domain name

Go to your nginx conf location with below commands

cd /etc/nginx/sites-available/

vi default

Replace the configuration file as below,

server_name _;

location / {

# First attempt to serve request as file, then

# as directory, then fall back to displaying a 404.

proxy_pass http://serverIP:4502;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

STEP #7: Now login to your domain registrar and point VPS server IP.

By now, you should be able to load your java application running on custom port via your domain name.

Please let us know if you have any questions!

Server Hosting Solutions by RackNerd:

Shared Hosting
cPanel Web Hosting in US, Europe, and Asia datacenters
Logo
Reseller Hosting
Create your new income stream today with a reseller account
Logo
VPS (Virtual Private Server)
Fast and Affordable VPS services - Instantly Deployed
Logo
Dedicated Servers
Bare-metal servers, ideal for the performance-demanding use case.
Logo

Leave a comment

Your email address will not be published. Required fields are marked *