How to Deploy Java Applications on a VPS
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:
|
We are using as our repo to store the code.
STEP #3: Create a directory and clone to repo
|
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
|
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.
|
and press Enter twice
You can see the application process running by command
|
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
|
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
|
Replace the configuration file as below,
|
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!