Nginx Reverse Proxy

Michael Mensah
5 min readMar 16, 2022

--

NGINX is open source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. It started out as a web server designed for maximum performance and stability. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

Source — https://www.nginx.com/resources/glossary/nginx/

The purpose of this project is to use Nginx as a load balance to route traffic to the app server where the java web application content is been hosted.

Launch your instances to begin the process. Name one of the server Nginx Server.

Configure your Tomcat server to serve your Java Web Application. Please see the screenshots below. Go to Tomcat website and copy the version of the application suggested by your developer. https://tomcat.apache.org/download-80.cgi

Login into your Tomcat server and copy the linked from the website with the command to download the file. — Wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.77/bin/apache-tomcat-8.5.77.zip

Use the command ls -la to see the content in the /opt folder and the command unzip apache-tomcat-8.5.77.zip to unzip the file and the cd command cd apache-tomcat-8.5.77/ to change directory.

Change directory to the bin folder to start server the Tomcat server with the command Chmod +x ./* to change permission of the scripts and then start server with the command ./startup .sh

Install OpenJDK with the command amazon-linux-extras java-openjdk11. Now that OpenJDK is installed we can now start our Tomcat server. Change directory to the bin folder and start Tomcat serer with the command ./startup.sh

Once you see the Tomcat browser started then this means your server has started successfully.

In the home directory of /opt/apache-tomcat-8.5.77 look for a folder call Webapps and change dir with the command cd webapps which is where the Java Web Application will be copied to from JFrog Artifactory.

Download the build application that was save in JFrog Artifactory to your webapps with the command wget and the URL from the JFrog account wget — — user= — — password= the URL copied from JFrog Artifactory

Press the ENTER key on your keyboard and yes the build Java web application is download to your tomcat server.

After the Java Web Application is deployed to the app server. The next step is to launch an NGINX server configure it and route traffic to the app server. Nginx can be install with the command amazon-linux-extras install nginx1 -y

After Nginx is install the configuration files will be stored in the etc location with the command cd to change directory cd /etc/nginx/ Start your Nginx server with the command.

Start the Nginx server with the command service Nginx start and check the status with command service Nginx status. Check the browser to see if Nginx is working.

Since am using Nginx server reserve proxy to help route traffic to the Java Web Application hosted in Tomcat to serve content to users. Nginx.conf is the location to go to make the necessary configuration changes to make your server as a reverse proxy. Use the command vi nginx.conf to make the changes in the configuration files.

To make the necessary changes on how to add a reserve proxy to the Nginx serve to route traffic to the backend Tomcat server. Type in Nginx Reverse Proxy pass documentation and go to the website and see how Nginx shows you how to add a request to an HTTP proxied served.

link — https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

To pass a request to an HTTP proxied server, the proxy pass directive is specified inside a location. For example: Make the necessary config changes by looking the steps below so that Nginx can revere proxy your traffic to the backend app service.

location /some/path/ {
proxy_pass http://www.example.com/link/;
}
location / {
proxy_pass http://3.88.158.15:8080/dptweb-1.0/;
}

After configuration have been completed stop your Nginx with the command Service Nginx stop and restart the Nginx back again with the command Service Nginx start. Now my Nginx serve is routing traffic from it server to Tomcat.

Conclusion — Now that my IP address and artifact is live in the Nginx confi folder content can now be served to users.. I can now add the Nginx IP as an A record or CNAME in the hosted zone in Route 53.

Thank you for stopping by to read my mini project with mensahCloud

--

--